Problems with Mutable

I am still struggling with this, even after reading all the posts about Mutables. I have a code block defining a map, which updates a tileset (d3-tile) and draws it to a canvas. But I want to look at the properties of the tileset, so I define it in a separate cell, as a Mutable.

When I zoom the map (d3-zoom), the map starts to move, and I can see the values change in the external cell, but then it immediately snaps back to the initial position. Is the whole map cell being re-initialized? Why?

If I declare the tileset inside the map cell, everything works fine. (using localTileSet instead of globalTileSet). But then I can’t access the tileset from a separate cell.

Any help is much appreciated :slight_smile:


Hi @jjhembd,

Here’s a one-word fix for the problem:

mutable globalTileSet is the non-reactive reference to the value.

globalTileSet is the reactive reference to the value. By using it, when you update its value a few lines above, that causes the entire map cell to be re-evaluated.

I hope that helps. Feel free to inquire further if things are still murky.

Here’s my take:

In short, use a side-effect cell to “listen” to the mutable changing, and trigger the call to redraw the tiles. That way you only need to redraw when the transform changes, rather than continuously.

(I also changed it to use the transform as the mutable rather than the tileset, since the tileset can always be computed from the transform.)

The one thing my fork doesn’t handle is that the tiles are loaded asynchronously, and there doesn’t seem to be an event (that I could tell?) when the tiles are available. So you’ll either need that, or you’ll need to go back to drawing the tiles continuously, but that seems wasteful…

Thanks a lot! Especially for those two phrases:

  • non-reactive reference
  • reactive reference

I think I’m starting to understand now… will have to play with it some more to be sure :slight_smile:

I like making the transform the mutable, this does make more sense.
And the tile cache does need to emit an event when tiles load.

Thanks for the quick responses!