wana
Version:
Easy observable state for React
52 lines (47 loc) • 1.14 kB
JavaScript
import { globals, $$, setHidden } from './815e560c.mjs';
import { is } from '@alloc/is';
let nextDebugId = 1;
const $D = Symbol.for("wana:debug");
function getCurrentAuto() {
return globals.auto;
}
function getDebug(target) {
return target[$D];
}
function setDebug(target, debug) {
debug.name += "#" + nextDebugId++;
target[$D] = debug;
return target;
}
function addDebugAction(target, action) {
const debug = getDebug(target);
if (debug && debug.actions) {
debug.actions.push(action);
}
}
function noto(effect) {
const {auto, observe} = globals;
globals.auto = null;
globals.observe = null;
try {
return effect();
} finally {
globals.auto = auto;
globals.observe = observe;
}
}
function no(value) {
if (is.function(value)) {
if (value[$$])
return value;
const fn = function(...args) {
return noto(value.bind(this, ...args));
};
setHidden(fn, "name", value.name);
setHidden(fn, $$, value);
return fn;
}
return value && value[$$] || value;
}
export { addDebugAction, getCurrentAuto, getDebug, no, noto, setDebug };
//# sourceMappingURL=6ab9b088.mjs.map