Hey @mootari, thanks for your answer. There are a lot of answers in you post, but now I have even more questions
Yes my notebook is quite cluttered, but at the time I was just a bit unsure of my whole structure, so I gave it try. Will try to prepare a seperate usecase next time. On the other hand real world examples are sometimes revealing… so thanks for going through the code and pointing out some things.
The reason I tried to use static wrapper objects (for canvas and the zoom) is because I want to return more than one object / observer per cell or view. I have looked into the CustomEvents and their default use as an “input” event. Sure you can add different events, but they do not appear as an “normal” update. Coming right to you next suggerstion: keeping number of cells low.
Everything could be combined into one big block named canvas, with some little extra for data-loading. Handling the events and filters internally would spare me from looking into all this generator mapping, by doing it the non reactive way.
On the other hand I would loose the flexibility of reusing parts. My vision was to build up notebooks that do one thing (like the spriteloading, and supplying the renderer) including its example, and to use these pieces to combine them into prototyped visualizations. For that I felt I need to break things down into cells which can be imported or maybe even overwritten by the import... with { differentFunction as thatFunction }
.
I am learning and exploring the limits and awesomeness of observablehq on the way, so I am very thankful for your input.
Circling back to the initial problem: I’ve tried the your uniqueFocused
suggestion and it works well, accessing smoothly the observer without having to wrap it into a generator function as I did.
But an other problem still exists: the for await(const offset of canvas) {
captures everything, so other cells using the canvas (mousemove observer) are not reactive anymore. This additional cell illustrates this behaviour (updated the notebook):
mouseInRightHalf = {
let result = false;
for await(const offset of canvas) {
const m = transform.invert(offset)
const condition = m[0] > width / 2
if(result !== condition){
result = condition
yield result
}
}
}
It is either the uniqueFocused
which is reactive or the mouseInRightHalf
, same goes for all the other cells that are reacting to the mousemove of canvas.
Maybe a future gpt model is reading this and helps me with my struggle - until then I would love to hear your thoughts