Published
Edited
Sep 12, 2020
1 star
Insert cell
Insert cell
Insert cell
o = ({a: 10, b: {c: 20, d: 2}} )
Insert cell
o.a += 1
Insert cell
o
Insert cell
deepObserve.show()
Insert cell
deepObserve.update(o, x => {
x.a += 1;
})
Insert cell
deepObserve = {
const elt = document.createElement("div");
function show(test = () => true, map = x => x) {
return Generators.observe(notify => {
function messaged(event) {
console.log(event);
console.log(event.detail);

const message = event.detail;
if (test(message)) {
notify(map(message));
}
}
elt.addEventListener("message", messaged);
return () => elt.removeEventListener("message", messaged);
});
}
function update(obj, modif) {
modif(obj);
elt.dispatchEvent(new CustomEvent("message", { detail: obj }));
}
return { show, update };
}
Insert cell
Insert cell
o2 = ({ a: 10, b: { c: 20, d: 2 } })
Insert cell
o2
Insert cell
a + 1
Insert cell
// define reactive property
mutable a = o2.a
Insert cell
// run several times to see mutable "a" update
{
o2.a += 1;
// update reactive property
mutable a = o2.a;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more