I am still relatively new to working with Observable and its reactive model, so apologies if the answer to this question is obvious.
I understand how I can use an input element to trigger a cell to update. For example:
viewof updateButton = Inputs.button("Update")
rand = {
updateButton; // Force recalculation when updateButton emits an input event
return Math.random();
}
However, it is not clear to me how I can do something similar when not using an input element. For example how might I get a click on a Canvas to trigger an update?
myCanvas = {
const ctx = DOM.context2d(200, 200);
d3.select(ctx.canvas).on("click", (evt) =>
console.log("How do I force rand to update?")
);
return ctx.canvas;
}
You can merge these things into a single thing with a viewof but it take a while to really grok this construction IMHO. It does highlight its HTML emitting âinputâ events is the fundamental signaling mechanism in Dataflow (mostly)
Thanks @tomlarkworthy , but thatâs not quite what I want (apologies if my question wasnât clear enough). I donât want to create any buttons (or other HTML input elements). Rather I want to be able dispatch the event generated by clicking on a canvas to another cell in order to force it to update itself. The example I provided used Button to do something similar, but I would like to use the click event on the Canvas instead.
Perfect thanks. Helpful in providing not only a working solution and reference article, but an indication of idiomatic event propagation in Observable.