UNPKG

woby

Version:

A high-performance framework with fine-grained observable/signal-based reactivity for building rich applications.

38 lines (37 loc) 1.01 kB
import { O as Owner, y as OWNER, z as SYMBOL_SUSPENSE, A as lazySetAdd, B as lazySetDelete, C as callStack } from "./setters-Ddu0s6oK.js"; class Root extends Owner { /* CONSTRUCTOR */ constructor(register) { super(); this.parent = OWNER; this.context = OWNER.context; if (register) { const suspense = this.get(SYMBOL_SUSPENSE); if (suspense) { this.registered = true; lazySetAdd(this.parent, "roots", this); } } } /* API */ dispose(deep) { if (this.registered) { lazySetDelete(this.parent, "roots", this); } super.dispose(deep); } wrap(fn, owner, observer, stack) { const dispose = () => this.dispose(true); const fnWithDispose = () => fn(stack, dispose); return super.wrap(fnWithDispose, this, void 0, stack); } } const root = (fn) => { const stack = callStack(); return new Root(true).wrap(fn, void 0, void 0, stack); }; export { Root as R, root as r }; //# sourceMappingURL=root-B8Ruf358.js.map