const main = new Runtime().module(notebook, name => {
if (name === "chart") {
return new Inspector(container);
}
});
main.redefine("data", newData);
but I wonder if it is the correct way to do.
At the point of redefining the data cell, maybe (?) the previous value of data would already have been used to evaluate other cells. And maybe (?) it would be better to have defined that value before launching any cell evaluation.
The snippet you posted will actually redefine the "data" cell before the original cell is evaluated and only newData will run. This is because the cell evaluation occurs in a promise which resolves after the main thread unblocks (see variable_define, which calls variable_defineImpl, which calls runtime_compute, which calls runtime_computeSoon).