Published
Edited
Mar 12, 2018
Insert cell
Insert cell
x
Insert cell
viewof x = new View([])
Insert cell
function test() {
viewof x.value = [];
for (let i=0; i<10; i++) {
let current_array = viewof x.value;
viewof x.value = [...current_array, i];
}
}
Insert cell
{
test();
}
Insert cell
class View {
constructor(value) {
this._list = [];
this._value = value;
}
get value() {
return this._value;
}
set value(value) {
this._value = value;
this.dispatchEvent({type: "input", value});
}
addEventListener(type, listener) {
if (type != "input" || this._list.includes(listener)) return;
this._list = [listener].concat(this._list);
}
removeEventListener(type, listener) {
if (type != "input") return;
this._list = this._list.filter(l => l !== listener);
}
dispatchEvent(event) {
const p = Promise.resolve(event);
this._list.forEach(l => p.then(l));
}
}
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