Published
Edited
Jun 3, 2020
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
new Error()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
CONTEXT_wrap_with_name = (name = 'Anonymous', fn) => {
return function() {
CONTEXT_NAME.current = name;
let result = fn.apply(this, arguments);
CONTEXT_NAME.current = null;
return result;
};
}
Insert cell
CONTEXT_parse_stack = () => {
if (CONTEXT_NAME.current == null) {
throw new Error(`Can't find current cell name in context`);
}
return CONTEXT_NAME.current;
}
Insert cell
Insert cell
Insert cell
Insert cell
PROPERTY_wrap_with_name = function(name = 'Anonymous', fn) {
let safe_name = `${function_name_prefix}[${name}]`;
try {
return new Function(
'call',
'name',
`return ({ [name]: function() { return call(this, arguments) } })[name]`
)(Function.apply.bind(fn), safe_name);
} catch (error) {
console.log(`Error setting "${safe_name}":`, error);
return fn;
}
}
Insert cell
PROPERTY_parse_stack = () => {
let stack = new Error().stack;
let matches = [
...stack.matchAll(
RegExp(`${function_name_prefix}\\[([a-zA-Z_$0-9 ]+)\]`, 'g')
)
].map(x => x[1]);

let name = matches[0];
if (name == null) {
throw new Error(`Couldn't find name in stack`);
}

return name;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
DEFINEPROPERTY_wrap_with_name = function(name = 'Anonymous', fn) {
let safe_name = `${function_name_prefix}[${name}]`;
Object.defineProperty(fn, "name", { value: safe_name });
return fn;
}
Insert cell
DEFINEPROPERTY_parse_stack = () => {
let stack = new Error().stack;
let matches = [
...stack.matchAll(
RegExp(`${function_name_prefix}\\[([a-zA-Z_$0-9 ]+)\]`, 'g')
)
].map(x => x[1]);

let name = matches[0];
if (name == null) {
throw new Error(`Couldn't find name in stack`);
}

return name;
}
Insert cell
Insert cell
Insert cell
Insert cell
FUNCTION_wrap_with_name = function(name = 'Anonymous', fn) {
let without_spaces = name.replace(/ /g, '_OBSERVABLE_SPACE_');
let safe_name = `__${function_name_prefix}__${without_spaces}__`;
try {
return new Function(
'call',
`return function ${safe_name}() { return call(this, arguments) };`
)(Function.apply.bind(fn));
} catch (error) {
console.log('safe_name:', safe_name);
return fn;
}
}
Insert cell
FUNCTION_parse_stack = () => {
let stack = new Error().stack;
let matches = [
...stack.matchAll(
RegExp(`__${function_name_prefix}__([a-zA-Z_$0-9 ]+)__`, 'g')
)
].map(x => x[1]);

let name = matches[0];
if (name == null) {
throw new Error(`Couldn't find name in stack`);
}

return name.replace(/_OBSERVABLE_SPACE_/g, ' ');
}
Insert cell
Insert cell
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