Published
Edited
Mar 30, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
rs`$place=(home|school)\n$name is at $place`
Insert cell
Insert cell
template = function(md, opts = {}) {
const assignRE = /\$([a-zA-Z0-9_]+)[\s]*=/g;
const symRE = /\$([a-zA-Z0-9_]+)/g;
let fun = (strs, ...vals) => {
try {
return RiTa.RiScript.eval((strs.reduce
((a, s, i) => a + s + (vals[i] || ''), '')), thisVarsObj);
}
catch (e) {
console.error('[RiScript] ' + e.message);
return '[RiScript] ' + e.message;
}
}
if (!md) return fun;
return (s, ...v) => {
let res = md`${fun(s, v)}`;
Array.from(res.children).forEach((e,i) => {
if (e.tagName === 'P') e.style['white-space'] = 'break-spaces';
});
return res;
}
}
Insert cell
Insert cell
mutable thisRuntime = captureRuntime
Insert cell
Insert cell
thisVarsObj = toContext(thisRuntime)
Insert cell
thisGlobalContext = ({
runtime: thisRuntime,
vars: thisVarsObj,
update: Generators.observe(change => {
const ele = html`<p></p>`;
//from https://observablehq.com/@mootari/observable-editor-events
const onMessage = ({data: d}) => {
if(d.type !== 'bundle') return;
// Strip offset_node events, as they can cause event loops (logging the
// the event triggers a height change, which triggers an event ...)
const events = d.events;
if(!events.length) return;
mutable thisRuntime = captureRuntime;
};
window.addEventListener('message', onMessage);
return () => window.removeEventListener('message', onMessage);
}),
})
Insert cell
Insert cell
Generators.observe(change => {
const ele = html`<p></p>`;
//from https://observablehq.com/@mootari/observable-editor-events
const onMessage = ({data: d}) => {
if(d.type !== 'bundle') return;
// Strip offset_node events, as they can cause event loops (logging the
// the event triggers a height change, which triggers an event ...)
const events = d.events;
if(!events.length) return;
mutable thisRuntime = captureRuntime;
};
window.addEventListener('message', onMessage);
return () => window.removeEventListener('message', onMessage);
})
Insert cell
import{thisRuntime as trigger} from '@real-john-cheung/test-rs'
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