Published unlisted
Edited
Dec 18, 2020
Importers
Insert cell
Insert cell
// Function to tell if a user has defined a value in their notebook
is_defined = cell_name => (variables.includes(cell_name) ? true : false)
Insert cell
a = 1
Insert cell
is_defined("a") // this is incorrect, but only on load(?)
Insert cell
// Detect node changes
Generators.observe(change => {
// change(get_variables()); // Trying to get this cell to not be blank on load?
const onMessage = ({ data: d }) => {
if (d.type !== 'bundle') return;
mutable variables = get_variables();
};

window.addEventListener('message', onMessage);
return () => window.removeEventListener('message', onMessage);
})
Insert cell
// Keep track of variables
mutable variables = get_variables()
Insert cell
get_variables = () =>
Array.from(runtime._variables)
.filter(v => v._name !== null && v._type === 1)
.map(v => v._name)
Insert cell
// import to trigger the scenario that allows capturing the Runtime on load
import { runtime as dummy } from '12e6887297f406bc' // still haven't wrapped my mind around the need for this
Insert cell
// 👉 You are here: https://github.com/observablehq/runtime/blob/c9ec40b/src/runtime.js#L231
// Removed console logs and debugger statements
runtime = {
let resolve;
const fn = Set.prototype.forEach,
p = new Promise(r => (resolve = r));
Set.prototype.forEach = function(...args) {
let o, runtime;

if ((o = args[1])) {
if (o._modules) {
runtime = o;
} else if (o._module) {
runtime = o._module._runtime;
}
} else if ((o = this[Symbol.iterator]().next().value) && o._module) {
runtime = o._module._runtime;
}

if (runtime) {
Set.prototype.forEach = fn;
resolve(runtime);
}
return fn.apply(this, args);
};
return p;
}
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