Feature request : destructuring assignment.

I’m adding some features to better integrate ganja.js as observable input and I noticed I can’t combine viewof and destructuring assignment.

viewof [a,b,c] = Algebra.graph(....)

Unless I’m missing something, the alternatives all -1*blow - I either have to use indexes instead of my clear and readable one-letter variable names (fun intended). - Or add a bunch of extra cells.

Of course in general destructuring assignment could clean up a lot of notebooks … there’s no value in needing 5 cells for something that could just be :

[point1,point2,point3,point4,target]=[[0,0],[0,1],[1,0],[1,1],[5,5]]

One for the wish-list :slight_smile:

4 Likes

Definitely! This is on our list and everyone’s very interested in making it happen as soon as we get a few less exciting tasks out of the way.

5 Likes

I’m relatively new to ObHQ, but really like it. I came here looking to see if (1) destructuring assignment works in general (is js blocks) and (2) if it works for viewof

I’m think this feature request is not as easy as it looks. For the destructured viewof [a,b,c], would you want them to be synchronized or not? Would it be like running 3 separate cells/code blocks? Or would you want them all be linked?

I ran some tests, and made some notes here: Try destructuring / chonghorizons / Observable

Conceptually, what would be the Inspector output (i.e. rendered cell output) for viewof [a, b, c]? And would this result in six internal variables (“viewof a”, “a”, “viewof b”, “b”, “viewof c”, “c”)? If not, how would you reference the viewof cell?

I’m so new that I’m not clear on internals and the reactivity. But here’s my guess:

  • you can reference a just as normal. same with b and c

  • Yes, there would be 6 internal variables, (“viewof a”, “a”, “viewof b”, “b”, “viewof c”, “c”)

  • Is there also something associated with the “anonymous” array viewof [a,b,c]?

  • The question about the “reactivity” is whether a, b, and c are linked and dataflow. If b is updated, does that dispatch an event (sorry if my terminology is off) for all the dataflow dependents on a and c too?

  • I made a notebook that might make these ideas clearer:
    test array as viewof as an array / chonghorizons / Observable

There is now a Github issue:

1 Like