So, what I did doesn’t really have anything to do with “viewof” specifically. I addressed an issue which is discussed in the tutorial “Observable anti-patterns and code smells”, namely that Observable cells generally should generally work with cell references rather than by querying the DOM.
Let me try to explain what this means for the earlier version of your notebook and my changes to it.
So what was happening previously was that the unnamed cell that called tippy
in the UI section had the following code:
tippy("#t2 td", {
content(reference) {
const title = reference.getAttribute('title');
reference.removeAttribute('title');
return title;
},
arrow: true,
size: 'large',
maxWidth: 120,
animation: 'fade',
placement: 'right',
})
This cell (which I’ll call the “tippy” cell) makes changes to the DOM element with id t2
. That DOM element is created by your table cell (which is named “viewof table
”). The fact that tippy acts on t2
, which is created by viewof table
means that the tippy cell should be re-run whenever viewof table
changes.
However, Observable has no way of knowing that! This is because the tippy cell doesn’t contain any references to viewof table
. When viewof table
is re-run, the tippy cell doesn’t react, since as far as the Observable runtime is concerned, they’re independent of each other. (See the tutorial How Observable runs for more about this.)
So in my fork, I added a reference to viewof table
in the tippy cell by turning it into this:
{
viewof table; // this doesn't really do anything,
// but it does tell the Observable runtime that this cell depends on "viewof table"
return tippy("#t2 td", {
content(reference) {
const title = reference.getAttribute('title');
reference.removeAttribute('title');
return title;
},
arrow: true,
size: 'large',
maxWidth: 120,
animation: 'fade',
placement: 'right',
});
}
(In hindsight I could have made this a bit more compact by using a comma, but let me not get into that now.)
After this change, the Observable runtime “knows” that the tippy cell depends on viewof table
and so when viewof table
is re-run, the tippy cell will run as well.
One way to visualize how the dependencies changed is to use the “Notebook visualizer”.
Here’s a link to a visualization of your original version. Note that you have to click the checkbox “anonymous cells” to see the tippy cell since it is unnamed. I believe it’s cell #31, and you can see there are no arrows from viewof table
to #31.
Here’s the link to a visualization of my fork. You can see that my edit creates an arrow from viewof table
to #31.
Glad I could help and feel free to ask if you have any more questions!