So I have a notebook with many cells that I want to update continuously, at a given interval, say 1 update per second (sync doesn’t matter). I’ve been doing this with multiple Promise.delay/yield calls, but the code gets messy quickly.
Is there a way to do this more cleanly (in a single place) for a notebook with many cells ?
But what if I wanted them to update one at a time? I’m thinking about graphical elements primarily, where I don’t want a big flash every second where everything changes at once…
Thanks for that, I now have a better understanding of the design thinking. And I may well be cutting against its grain, but I still think the use case is… useful. Ideally I could provide an array of cell-names (the slowly updating graphical elements), and have each updated every K milliseconds, but with a unique offset for each, so they don’t all trigger at once.
Q: is there a way to programmatically force an update of a cell from another cell (without cross-cell references ) ?
Hmm, I see how it might be done by iteration over the runtime _variables property and finding the desired cells, but, as you say, it is working quite against the observable grain…
One other question: is there a way to disable propagation of updates to downstream references of a cell?
My guess is that your answer is the same: likely possible, but not in an intended/idiomatic way.
You can return an unresolved promise to “skip” updates.
Another useful expression is “this” which refers to the previous value of a cell. So if you wanted to skip an update based on the previous state without introducing an adjacent cell to carry over state you might use ‘this’.
If the update is triggered by a parent cell, then no:
Yes you can, return new Promise(() => {}) in the child to skip propagating an update when a parent updates.
“The previously-resolved value continues to be visible to other cells until the newly-yielded value resolves: in other words, a generator cell’s apparent value is the most-recently resolved value. For example, if you have a slowly-incrementing counter, you can reference it from another cell and see the current count instantly, rather than waiting for the next tick.” – Mike Bostock
in Introduction to generators / Observable | Observable
Imo that’s only marginally useful, since any downstream cell will still be invalidated. So it’s fine for one-off cells that only compute a value, but any generator, including viewof cells, will stop producing values.
I too was worried that if a cell is streaming out unresolved promises then dependants would just in an undefined state, but thats why I linked to what Mike Bosock said. It seems the runtime caches the last known value so they just work off the old value until a new one is actually resolved. Intermediate unresolved promises don’t cause an update to downstream cells. Its very cool that it works!