@estjs/template 0.0.15-beta.14 → 0.0.15-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-3E4EK64L.dev.esm.js +152 -0
- package/dist/chunk-3E4EK64L.dev.esm.js.map +1 -0
- package/dist/chunk-IRDMO5MX.esm.js +2 -0
- package/dist/chunk-IRDMO5MX.esm.js.map +1 -0
- package/dist/internal-Bz6h0aPa.d.cts +84 -0
- package/dist/internal-Bz6h0aPa.d.ts +84 -0
- package/dist/internal.cjs.js +2 -0
- package/dist/internal.cjs.js.map +1 -0
- package/dist/internal.d.cts +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.dev.cjs.js +110 -0
- package/dist/internal.dev.cjs.js.map +1 -0
- package/dist/internal.dev.esm.js +3 -0
- package/dist/internal.dev.esm.js.map +1 -0
- package/dist/internal.esm.js +2 -0
- package/dist/internal.esm.js.map +1 -0
- package/dist/template.cjs.js +2 -2
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +421 -368
- package/dist/template.d.ts +421 -368
- package/dist/template.dev.cjs.js +1519 -1364
- package/dist/template.dev.cjs.js.map +1 -1
- package/dist/template.dev.esm.js +1434 -1420
- package/dist/template.dev.esm.js.map +1 -1
- package/dist/template.esm.js +2 -2
- package/dist/template.esm.js.map +1 -1
- package/package.json +13 -3
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { error } from '@estjs/shared';
|
|
2
|
+
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __objRest = (source, exclude) => {
|
|
7
|
+
var target = {};
|
|
8
|
+
for (var prop in source)
|
|
9
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
10
|
+
target[prop] = source[prop];
|
|
11
|
+
if (source != null && __getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
13
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
14
|
+
target[prop] = source[prop];
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var activeScope = null;
|
|
39
|
+
var scopeId = 0;
|
|
40
|
+
function getActiveScope() {
|
|
41
|
+
return activeScope;
|
|
42
|
+
}
|
|
43
|
+
function createScope(parent = activeScope) {
|
|
44
|
+
const scope = {
|
|
45
|
+
id: ++scopeId,
|
|
46
|
+
parent,
|
|
47
|
+
children: null,
|
|
48
|
+
// Lazy initialized
|
|
49
|
+
provides: null,
|
|
50
|
+
// Lazy initialized
|
|
51
|
+
cleanup: null,
|
|
52
|
+
// Lazy initialized
|
|
53
|
+
onMount: null,
|
|
54
|
+
// Lazy initialized
|
|
55
|
+
onUpdate: null,
|
|
56
|
+
// Lazy initialized
|
|
57
|
+
onDestroy: null,
|
|
58
|
+
// Lazy initialized
|
|
59
|
+
isMounted: false,
|
|
60
|
+
isDestroyed: false
|
|
61
|
+
};
|
|
62
|
+
if (parent) {
|
|
63
|
+
if (!parent.children) {
|
|
64
|
+
parent.children = /* @__PURE__ */ new Set();
|
|
65
|
+
}
|
|
66
|
+
parent.children.add(scope);
|
|
67
|
+
}
|
|
68
|
+
return scope;
|
|
69
|
+
}
|
|
70
|
+
function runWithScope(scope, fn) {
|
|
71
|
+
const prevScope = activeScope;
|
|
72
|
+
activeScope = scope;
|
|
73
|
+
try {
|
|
74
|
+
return fn();
|
|
75
|
+
} finally {
|
|
76
|
+
activeScope = prevScope;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function disposeScope(scope) {
|
|
80
|
+
var _a;
|
|
81
|
+
if (!scope || scope.isDestroyed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
scope.isDestroyed = true;
|
|
85
|
+
if (scope.children && scope.children.size > 0) {
|
|
86
|
+
for (const child of scope.children) {
|
|
87
|
+
if (child) {
|
|
88
|
+
child.parent = null;
|
|
89
|
+
disposeScope(child);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
scope.children.clear();
|
|
93
|
+
}
|
|
94
|
+
const prevScope = activeScope;
|
|
95
|
+
activeScope = scope;
|
|
96
|
+
try {
|
|
97
|
+
if (scope.onDestroy) {
|
|
98
|
+
for (let i = 0; i < scope.onDestroy.length; i++) {
|
|
99
|
+
try {
|
|
100
|
+
scope.onDestroy[i]();
|
|
101
|
+
} catch (error_) {
|
|
102
|
+
if (true) {
|
|
103
|
+
error(`Scope(${scope.id}): Error in destroy hook:`, error_);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
scope.onDestroy = null;
|
|
108
|
+
}
|
|
109
|
+
if (scope.cleanup) {
|
|
110
|
+
for (let i = 0; i < scope.cleanup.length; i++) {
|
|
111
|
+
try {
|
|
112
|
+
scope.cleanup[i]();
|
|
113
|
+
} catch (error_) {
|
|
114
|
+
if (true) {
|
|
115
|
+
error(`Scope(${scope.id}): Error in cleanup:`, error_);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
scope.cleanup = null;
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
activeScope = prevScope;
|
|
123
|
+
}
|
|
124
|
+
if ((_a = scope.parent) == null ? void 0 : _a.children) {
|
|
125
|
+
scope.parent.children.delete(scope);
|
|
126
|
+
}
|
|
127
|
+
if (scope.provides) {
|
|
128
|
+
scope.provides.clear();
|
|
129
|
+
scope.provides = null;
|
|
130
|
+
}
|
|
131
|
+
scope.onMount = null;
|
|
132
|
+
scope.onUpdate = null;
|
|
133
|
+
scope.children = null;
|
|
134
|
+
scope.parent = null;
|
|
135
|
+
}
|
|
136
|
+
function onCleanup(fn) {
|
|
137
|
+
const scope = activeScope;
|
|
138
|
+
if (!scope) {
|
|
139
|
+
{
|
|
140
|
+
error("onCleanup() must be called within a scope");
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!scope.cleanup) {
|
|
145
|
+
scope.cleanup = [];
|
|
146
|
+
}
|
|
147
|
+
scope.cleanup.push(fn);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { __async, __objRest, createScope, disposeScope, getActiveScope, onCleanup, runWithScope };
|
|
151
|
+
//# sourceMappingURL=chunk-3E4EK64L.dev.esm.js.map
|
|
152
|
+
//# sourceMappingURL=chunk-3E4EK64L.dev.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scope.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAI,WAAA,GAA4B,IAAA;AAGhC,IAAI,OAAA,GAAU,CAAA;AAOP,SAAS,cAAA,GAA+B;AAC7C,EAAA,OAAO,WAAA;AACT;AAmBO,SAAS,WAAA,CAAY,SAAuB,WAAA,EAAoB;AACrE,EAAA,MAAM,KAAA,GAAe;AAAA,IACnB,IAAI,EAAE,OAAA;AAAA,IACN,MAAA;AAAA,IACA,QAAA,EAAU,IAAA;AAAA;AAAA,IACV,Q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,MAAM,QAAA,EAAU;AAClB,IAAA,KAAA,CAAM,SAAS,KAAA,EAAM;AACrB,IAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AAAA,EACnB;AACA,EAAA,KAAA,CAAM,OAAA,GAAU,IAAA;AAChB,EAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AACjB,EAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AAGjB,EAAA,KAAA,CAAM,MAAA,GAAS,IAAA;AACjB;AAQO,SAAS,UAAU,EAAA,EAAsB;AAC9C,EAAA,MAAM,KAAA,GAAQ,WAAA;AAEd,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAa;AACX,MAAA,KAAA,CAAM,2CAA2C,CAAA;AAAA,IACnD;AACA,IAAA;AAAA,EACF;AAGA,EAAA,IAAI,CAAC,MAAM,OAAA,EAAS;AAClB,IAAA,KAAA,CAAM,UAAU,EAAC;AAAA,EACnB;AAEA,EAAA,KAAA,CAAM,OAAA,CAAQ,KAAK,EAAE,CAAA;AACvB","file":"chunk-3E4EK64L.dev.esm.js","sourcesContent":["import { error } from '@estjs/shared';\nimport type { InjectionKey } from './provide';\n\n/**\n * Scope represents an execution context in the component tree.\n * It manages provides, cleanup functions, and lifecycle hooks.\n */\nexport interface Scope {\n /** Unique identifier for debugging */\n readonly id: number;\n\n /** Parent scope in the hierarchy */\n parent: Scope | null;\n\n /** Child scopes (lazy initialized) */\n children: Set<Scope> | null;\n\n /** Provided values (lazy initialized) */\n provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;\n\n /** Cleanup functions (lazy initialized) */\n cleanup: Array<() => void> | null;\n\n /** Mount lifecycle hooks (lazy initialized) */\n onMount: Array<() => void | Promise<void>> | null;\n\n /** Update lifecycle hooks (lazy initialized) */\n onUpdate: Array<() => void | Promise<void>> | null;\n\n /** Destroy lifecycle hooks (lazy initialized) */\n onDestroy: Array<() => void | Promise<void>> | null;\n\n /** Whether the scope has been mounted */\n isMounted: boolean;\n\n /** Whether the scope has been destroyed */\n isDestroyed: boolean;\n}\n\n/** Currently active scope */\nlet activeScope: Scope | null = null;\n\n/** Scope ID counter for unique identification */\nlet scopeId = 0;\n\n/**\n * Get the currently active scope.\n *\n * @returns The active scope or null if none is active.\n */\nexport function getActiveScope(): Scope | null {\n return activeScope;\n}\n\n/**\n * Set the active scope (internal use).\n *\n * @param scope - The scope to set as active.\n * @returns {void}\n */\nexport function setActiveScope(scope: Scope | null): void {\n activeScope = scope;\n}\n\n/**\n * Create a new scope with optional parent.\n * If no parent is provided, uses the current active scope as parent.\n *\n * @param parent - Optional parent scope (defaults to active scope).\n * @returns A new scope instance.\n */\nexport function createScope(parent: Scope | null = activeScope): Scope {\n const scope: Scope = {\n id: ++scopeId,\n parent,\n children: null, // Lazy initialized\n provides: null, // Lazy initialized\n cleanup: null, // Lazy initialized\n onMount: null, // Lazy initialized\n onUpdate: null, // Lazy initialized\n onDestroy: null, // Lazy initialized\n isMounted: false,\n isDestroyed: false,\n };\n\n // Establish parent-child relationship\n if (parent) {\n if (!parent.children) {\n parent.children = new Set();\n }\n parent.children.add(scope);\n }\n\n return scope;\n}\n\n/**\n * Run a function within a scope, ensuring proper cleanup.\n * The previous active scope is restored even if the function throws.\n *\n * @param scope - The scope to run within.\n * @param fn - The function to execute.\n * @returns The return value of the function.\n */\nexport function runWithScope<T>(scope: Scope, fn: () => T): T {\n const prevScope = activeScope;\n activeScope = scope;\n\n try {\n return fn();\n } finally {\n // Restore previous scope directly\n activeScope = prevScope;\n }\n}\n\n/**\n * Dispose a scope and all its children.\n * Children are disposed first (depth-first), then the scope itself.\n *\n * @param scope - The scope to dispose.\n * @returns {void}\n */\nexport function disposeScope(scope: Scope): void {\n // Idempotent: already destroyed\n if (!scope || scope.isDestroyed) {\n return;\n }\n\n // Mark destroyed immediately to block re-entrant disposeScope calls\n // (e.g. an onDestroy hook that accidentally disposes the same scope again).\n scope.isDestroyed = true;\n\n // Dispose children first (depth-first)\n // Iterate directly safely by unlinking parent reference to prevent mutation during iteration\n if (scope.children && scope.children.size > 0) {\n for (const child of scope.children) {\n if (child) {\n child.parent = null;\n disposeScope(child);\n }\n }\n scope.children.clear();\n }\n\n // Execute destroy lifecycle hooks and cleanup functions within the scope's\n // context so that inject/provide/getActiveScope work correctly in callbacks.\n //\n // We inline the scope-switching instead of calling `runWithScope()` to avoid\n // an extra function frame on the teardown hot path (disposeScope is called\n // recursively for every child scope in the tree).\n //\n // NOTE: `scope.isDestroyed` is already `true` at this point — this is\n // intentional to prevent re-entrant `disposeScope()` calls from within\n // hooks. Callbacks that inspect `getActiveScope()?.isDestroyed` should\n // be aware of this.\n const prevScope = activeScope;\n activeScope = scope;\n try {\n // Execute destroy lifecycle hooks\n if (scope.onDestroy) {\n for (let i = 0; i < scope.onDestroy.length; i++) {\n try {\n scope.onDestroy[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in destroy hook:`, error_);\n }\n }\n }\n scope.onDestroy = null;\n }\n\n // Execute cleanup functions\n if (scope.cleanup) {\n for (let i = 0; i < scope.cleanup.length; i++) {\n try {\n scope.cleanup[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in cleanup:`, error_);\n }\n }\n }\n scope.cleanup = null;\n }\n } finally {\n activeScope = prevScope;\n }\n\n // Remove from parent's children\n if (scope.parent?.children) {\n scope.parent.children.delete(scope);\n }\n\n // Clear all internal collections to prevent memory leaks\n if (scope.provides) {\n scope.provides.clear();\n scope.provides = null;\n }\n scope.onMount = null;\n scope.onUpdate = null;\n scope.children = null;\n\n // Break parent reference to prevent memory leaks\n scope.parent = null;\n}\n\n/**\n * Register a cleanup function in the current scope.\n * The function will be called when the scope is disposed.\n *\n * @param fn - The cleanup function.\n */\nexport function onCleanup(fn: () => void): void {\n const scope = activeScope;\n\n if (!scope) {\n if (__DEV__) {\n error('onCleanup() must be called within a scope');\n }\n return;\n }\n\n // Lazy initialize cleanup array\n if (!scope.cleanup) {\n scope.cleanup = [];\n }\n\n scope.cleanup.push(fn);\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import'@estjs/shared';var c=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var h=(e,r)=>{var o={};for(var n in e)f.call(e,n)&&r.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&c)for(var n of c(e))r.indexOf(n)<0&&y.call(e,n)&&(o[n]=e[n]);return o};var s=(e,r,o)=>new Promise((n,t)=>{var p=i=>{try{u(o.next(i));}catch(d){t(d);}},a=i=>{try{u(o.throw(i));}catch(d){t(d);}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(p,a);u((o=o.apply(e,r)).next());});var l=null,S=0;function A(){return l}function M(e=l){let r={id:++S,parent:e,children:null,provides:null,cleanup:null,onMount:null,onUpdate:null,onDestroy:null,isMounted:false,isDestroyed:false};return e&&(e.children||(e.children=new Set),e.children.add(r)),r}function E(e,r){let o=l;l=e;try{return r()}finally{l=o;}}function v(e){var o;if(!e||e.isDestroyed)return;if(e.isDestroyed=true,e.children&&e.children.size>0){for(let n of e.children)n&&(n.parent=null,v(n));e.children.clear();}let r=l;l=e;try{if(e.onDestroy){for(let n=0;n<e.onDestroy.length;n++)try{e.onDestroy[n]();}catch(t){}e.onDestroy=null;}if(e.cleanup){for(let n=0;n<e.cleanup.length;n++)try{e.cleanup[n]();}catch(t){}e.cleanup=null;}}finally{l=r;}(o=e.parent)!=null&&o.children&&e.parent.children.delete(e),e.provides&&(e.provides.clear(),e.provides=null),e.onMount=null,e.onUpdate=null,e.children=null,e.parent=null;}function g(e){let r=l;r&&(r.cleanup||(r.cleanup=[]),r.cleanup.push(e));}export{h as a,s as b,A as c,M as d,E as e,v as f,g};//# sourceMappingURL=chunk-IRDMO5MX.esm.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-IRDMO5MX.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scope.ts"],"names":["activeScope","scopeId","getActiveScope","createScope","parent","scope","runWithScope","fn","prevScope","disposeScope","_a","child","i","error_","onCleanup"],"mappings":"2fAwCA,IAAIA,CAAAA,CAA4B,IAAA,CAG5BC,CAAAA,CAAU,EAOP,SAASC,CAAAA,EAA+B,CAC7C,OAAOF,CACT,CAmBO,SAASG,CAAAA,CAAYC,CAAAA,CAAuBJ,CAAAA,CAAoB,CACrE,IAAMK,CAAAA,CAAe,CACnB,EAAA,CAAI,EAAEJ,CAAAA,CACN,MAAA,CAAAG,CAAAA,CACA,QAAA,CAAU,IAAA,CACV,SAAU,IAAA,CACV,OAAA,CAAS,IAAA,CACT,OAAA,CAAS,IAAA,CACT,QAAA,CAAU,IAAA,CACV,SAAA,CAAW,IAAA,CACX,SAAA,CAAW,KAAA,CACX,WAAA,CAAa,KACf,CAAA,CAGA,OAAIA,CAAAA,GACGA,CAAAA,CAAO,QAAA,GACVA,CAAAA,CAAO,QAAA,CAAW,IAAI,GAAA,CAAA,CAExBA,CAAAA,CAAO,QAAA,CAAS,GAAA,CAAIC,CAAK,CAAA,CAAA,CAGpBA,CACT,CAUO,SAASC,CAAAA,CAAgBD,CAAAA,CAAcE,CAAAA,CAAgB,CAC5D,IAAMC,CAAAA,CAAYR,CAAAA,CAClBA,CAAAA,CAAcK,CAAAA,CAEd,GAAI,CACF,OAAOE,CAAAA,EACT,QAAE,CAEAP,CAAAA,CAAcQ,EAChB,CACF,CASO,SAASC,CAAAA,CAAaJ,CAAAA,CAAoB,CA3HjD,IAAAK,CAAAA,CA6HE,GAAI,CAACL,CAAAA,EAASA,EAAM,WAAA,CAClB,OASF,GAJAA,CAAAA,CAAM,WAAA,CAAc,IAAA,CAIhBA,CAAAA,CAAM,QAAA,EAAYA,CAAAA,CAAM,QAAA,CAAS,IAAA,CAAO,CAAA,CAAG,CAC7C,IAAA,IAAWM,KAASN,CAAAA,CAAM,QAAA,CACpBM,CAAAA,GACFA,CAAAA,CAAM,MAAA,CAAS,IAAA,CACfF,CAAAA,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AQAA,CAAAA,CAAM,OAAA,GACTA,CAAAA,CAAM,OAAA,CAAU,EAAC,CAAA,CAGnBA,CAAAA,CAAM,OAAA,CAAQ,IAAA,CAAKE,CAAE,CAAA,EACvB","file":"chunk-IRDMO5MX.esm.js","sourcesContent":["import { error } from '@estjs/shared';\nimport type { InjectionKey } from './provide';\n\n/**\n * Scope represents an execution context in the component tree.\n * It manages provides, cleanup functions, and lifecycle hooks.\n */\nexport interface Scope {\n /** Unique identifier for debugging */\n readonly id: number;\n\n /** Parent scope in the hierarchy */\n parent: Scope | null;\n\n /** Child scopes (lazy initialized) */\n children: Set<Scope> | null;\n\n /** Provided values (lazy initialized) */\n provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;\n\n /** Cleanup functions (lazy initialized) */\n cleanup: Array<() => void> | null;\n\n /** Mount lifecycle hooks (lazy initialized) */\n onMount: Array<() => void | Promise<void>> | null;\n\n /** Update lifecycle hooks (lazy initialized) */\n onUpdate: Array<() => void | Promise<void>> | null;\n\n /** Destroy lifecycle hooks (lazy initialized) */\n onDestroy: Array<() => void | Promise<void>> | null;\n\n /** Whether the scope has been mounted */\n isMounted: boolean;\n\n /** Whether the scope has been destroyed */\n isDestroyed: boolean;\n}\n\n/** Currently active scope */\nlet activeScope: Scope | null = null;\n\n/** Scope ID counter for unique identification */\nlet scopeId = 0;\n\n/**\n * Get the currently active scope.\n *\n * @returns The active scope or null if none is active.\n */\nexport function getActiveScope(): Scope | null {\n return activeScope;\n}\n\n/**\n * Set the active scope (internal use).\n *\n * @param scope - The scope to set as active.\n * @returns {void}\n */\nexport function setActiveScope(scope: Scope | null): void {\n activeScope = scope;\n}\n\n/**\n * Create a new scope with optional parent.\n * If no parent is provided, uses the current active scope as parent.\n *\n * @param parent - Optional parent scope (defaults to active scope).\n * @returns A new scope instance.\n */\nexport function createScope(parent: Scope | null = activeScope): Scope {\n const scope: Scope = {\n id: ++scopeId,\n parent,\n children: null, // Lazy initialized\n provides: null, // Lazy initialized\n cleanup: null, // Lazy initialized\n onMount: null, // Lazy initialized\n onUpdate: null, // Lazy initialized\n onDestroy: null, // Lazy initialized\n isMounted: false,\n isDestroyed: false,\n };\n\n // Establish parent-child relationship\n if (parent) {\n if (!parent.children) {\n parent.children = new Set();\n }\n parent.children.add(scope);\n }\n\n return scope;\n}\n\n/**\n * Run a function within a scope, ensuring proper cleanup.\n * The previous active scope is restored even if the function throws.\n *\n * @param scope - The scope to run within.\n * @param fn - The function to execute.\n * @returns The return value of the function.\n */\nexport function runWithScope<T>(scope: Scope, fn: () => T): T {\n const prevScope = activeScope;\n activeScope = scope;\n\n try {\n return fn();\n } finally {\n // Restore previous scope directly\n activeScope = prevScope;\n }\n}\n\n/**\n * Dispose a scope and all its children.\n * Children are disposed first (depth-first), then the scope itself.\n *\n * @param scope - The scope to dispose.\n * @returns {void}\n */\nexport function disposeScope(scope: Scope): void {\n // Idempotent: already destroyed\n if (!scope || scope.isDestroyed) {\n return;\n }\n\n // Mark destroyed immediately to block re-entrant disposeScope calls\n // (e.g. an onDestroy hook that accidentally disposes the same scope again).\n scope.isDestroyed = true;\n\n // Dispose children first (depth-first)\n // Iterate directly safely by unlinking parent reference to prevent mutation during iteration\n if (scope.children && scope.children.size > 0) {\n for (const child of scope.children) {\n if (child) {\n child.parent = null;\n disposeScope(child);\n }\n }\n scope.children.clear();\n }\n\n // Execute destroy lifecycle hooks and cleanup functions within the scope's\n // context so that inject/provide/getActiveScope work correctly in callbacks.\n //\n // We inline the scope-switching instead of calling `runWithScope()` to avoid\n // an extra function frame on the teardown hot path (disposeScope is called\n // recursively for every child scope in the tree).\n //\n // NOTE: `scope.isDestroyed` is already `true` at this point — this is\n // intentional to prevent re-entrant `disposeScope()` calls from within\n // hooks. Callbacks that inspect `getActiveScope()?.isDestroyed` should\n // be aware of this.\n const prevScope = activeScope;\n activeScope = scope;\n try {\n // Execute destroy lifecycle hooks\n if (scope.onDestroy) {\n for (let i = 0; i < scope.onDestroy.length; i++) {\n try {\n scope.onDestroy[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in destroy hook:`, error_);\n }\n }\n }\n scope.onDestroy = null;\n }\n\n // Execute cleanup functions\n if (scope.cleanup) {\n for (let i = 0; i < scope.cleanup.length; i++) {\n try {\n scope.cleanup[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in cleanup:`, error_);\n }\n }\n }\n scope.cleanup = null;\n }\n } finally {\n activeScope = prevScope;\n }\n\n // Remove from parent's children\n if (scope.parent?.children) {\n scope.parent.children.delete(scope);\n }\n\n // Clear all internal collections to prevent memory leaks\n if (scope.provides) {\n scope.provides.clear();\n scope.provides = null;\n }\n scope.onMount = null;\n scope.onUpdate = null;\n scope.children = null;\n\n // Break parent reference to prevent memory leaks\n scope.parent = null;\n}\n\n/**\n * Register a cleanup function in the current scope.\n * The function will be called when the scope is disposed.\n *\n * @param fn - The cleanup function.\n */\nexport function onCleanup(fn: () => void): void {\n const scope = activeScope;\n\n if (!scope) {\n if (__DEV__) {\n error('onCleanup() must be called within a scope');\n }\n return;\n }\n\n // Lazy initialize cleanup array\n if (!scope.cleanup) {\n scope.cleanup = [];\n }\n\n scope.cleanup.push(fn);\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InjectionKey is a unique identifier for provided values.
|
|
3
|
+
* Using Symbol ensures type safety and prevents key collisions.
|
|
4
|
+
*/
|
|
5
|
+
interface InjectionKey<T> extends Symbol {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Provide a value in the current scope.
|
|
9
|
+
* The value can be injected by this scope or any descendant scope.
|
|
10
|
+
*
|
|
11
|
+
* @param key - The injection key.
|
|
12
|
+
* @param value - The value to provide.
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
15
|
+
declare function provide<T>(key: InjectionKey<T> | string | number, value: T): void;
|
|
16
|
+
/**
|
|
17
|
+
* Inject a value from the scope hierarchy.
|
|
18
|
+
* Traverses up the parent chain until finding a matching key.
|
|
19
|
+
*
|
|
20
|
+
* @param key - The injection key.
|
|
21
|
+
* @param defaultValue - Default value if key is not found.
|
|
22
|
+
* @returns The injected value or default value.
|
|
23
|
+
*/
|
|
24
|
+
declare function inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Scope represents an execution context in the component tree.
|
|
28
|
+
* It manages provides, cleanup functions, and lifecycle hooks.
|
|
29
|
+
*/
|
|
30
|
+
interface Scope {
|
|
31
|
+
/** Unique identifier for debugging */
|
|
32
|
+
readonly id: number;
|
|
33
|
+
/** Parent scope in the hierarchy */
|
|
34
|
+
parent: Scope | null;
|
|
35
|
+
/** Child scopes (lazy initialized) */
|
|
36
|
+
children: Set<Scope> | null;
|
|
37
|
+
/** Provided values (lazy initialized) */
|
|
38
|
+
provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;
|
|
39
|
+
/** Cleanup functions (lazy initialized) */
|
|
40
|
+
cleanup: Array<() => void> | null;
|
|
41
|
+
/** Mount lifecycle hooks (lazy initialized) */
|
|
42
|
+
onMount: Array<() => void | Promise<void>> | null;
|
|
43
|
+
/** Update lifecycle hooks (lazy initialized) */
|
|
44
|
+
onUpdate: Array<() => void | Promise<void>> | null;
|
|
45
|
+
/** Destroy lifecycle hooks (lazy initialized) */
|
|
46
|
+
onDestroy: Array<() => void | Promise<void>> | null;
|
|
47
|
+
/** Whether the scope has been mounted */
|
|
48
|
+
isMounted: boolean;
|
|
49
|
+
/** Whether the scope has been destroyed */
|
|
50
|
+
isDestroyed: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the currently active scope.
|
|
54
|
+
*
|
|
55
|
+
* @returns The active scope or null if none is active.
|
|
56
|
+
*/
|
|
57
|
+
declare function getActiveScope(): Scope | null;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new scope with optional parent.
|
|
60
|
+
* If no parent is provided, uses the current active scope as parent.
|
|
61
|
+
*
|
|
62
|
+
* @param parent - Optional parent scope (defaults to active scope).
|
|
63
|
+
* @returns A new scope instance.
|
|
64
|
+
*/
|
|
65
|
+
declare function createScope(parent?: Scope | null): Scope;
|
|
66
|
+
/**
|
|
67
|
+
* Run a function within a scope, ensuring proper cleanup.
|
|
68
|
+
* The previous active scope is restored even if the function throws.
|
|
69
|
+
*
|
|
70
|
+
* @param scope - The scope to run within.
|
|
71
|
+
* @param fn - The function to execute.
|
|
72
|
+
* @returns The return value of the function.
|
|
73
|
+
*/
|
|
74
|
+
declare function runWithScope<T>(scope: Scope, fn: () => T): T;
|
|
75
|
+
/**
|
|
76
|
+
* Dispose a scope and all its children.
|
|
77
|
+
* Children are disposed first (depth-first), then the scope itself.
|
|
78
|
+
*
|
|
79
|
+
* @param scope - The scope to dispose.
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
declare function disposeScope(scope: Scope): void;
|
|
83
|
+
|
|
84
|
+
export { type InjectionKey as I, type Scope as S, createScope as c, disposeScope as d, getActiveScope as g, inject as i, provide as p, runWithScope as r };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InjectionKey is a unique identifier for provided values.
|
|
3
|
+
* Using Symbol ensures type safety and prevents key collisions.
|
|
4
|
+
*/
|
|
5
|
+
interface InjectionKey<T> extends Symbol {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Provide a value in the current scope.
|
|
9
|
+
* The value can be injected by this scope or any descendant scope.
|
|
10
|
+
*
|
|
11
|
+
* @param key - The injection key.
|
|
12
|
+
* @param value - The value to provide.
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
15
|
+
declare function provide<T>(key: InjectionKey<T> | string | number, value: T): void;
|
|
16
|
+
/**
|
|
17
|
+
* Inject a value from the scope hierarchy.
|
|
18
|
+
* Traverses up the parent chain until finding a matching key.
|
|
19
|
+
*
|
|
20
|
+
* @param key - The injection key.
|
|
21
|
+
* @param defaultValue - Default value if key is not found.
|
|
22
|
+
* @returns The injected value or default value.
|
|
23
|
+
*/
|
|
24
|
+
declare function inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Scope represents an execution context in the component tree.
|
|
28
|
+
* It manages provides, cleanup functions, and lifecycle hooks.
|
|
29
|
+
*/
|
|
30
|
+
interface Scope {
|
|
31
|
+
/** Unique identifier for debugging */
|
|
32
|
+
readonly id: number;
|
|
33
|
+
/** Parent scope in the hierarchy */
|
|
34
|
+
parent: Scope | null;
|
|
35
|
+
/** Child scopes (lazy initialized) */
|
|
36
|
+
children: Set<Scope> | null;
|
|
37
|
+
/** Provided values (lazy initialized) */
|
|
38
|
+
provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;
|
|
39
|
+
/** Cleanup functions (lazy initialized) */
|
|
40
|
+
cleanup: Array<() => void> | null;
|
|
41
|
+
/** Mount lifecycle hooks (lazy initialized) */
|
|
42
|
+
onMount: Array<() => void | Promise<void>> | null;
|
|
43
|
+
/** Update lifecycle hooks (lazy initialized) */
|
|
44
|
+
onUpdate: Array<() => void | Promise<void>> | null;
|
|
45
|
+
/** Destroy lifecycle hooks (lazy initialized) */
|
|
46
|
+
onDestroy: Array<() => void | Promise<void>> | null;
|
|
47
|
+
/** Whether the scope has been mounted */
|
|
48
|
+
isMounted: boolean;
|
|
49
|
+
/** Whether the scope has been destroyed */
|
|
50
|
+
isDestroyed: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the currently active scope.
|
|
54
|
+
*
|
|
55
|
+
* @returns The active scope or null if none is active.
|
|
56
|
+
*/
|
|
57
|
+
declare function getActiveScope(): Scope | null;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new scope with optional parent.
|
|
60
|
+
* If no parent is provided, uses the current active scope as parent.
|
|
61
|
+
*
|
|
62
|
+
* @param parent - Optional parent scope (defaults to active scope).
|
|
63
|
+
* @returns A new scope instance.
|
|
64
|
+
*/
|
|
65
|
+
declare function createScope(parent?: Scope | null): Scope;
|
|
66
|
+
/**
|
|
67
|
+
* Run a function within a scope, ensuring proper cleanup.
|
|
68
|
+
* The previous active scope is restored even if the function throws.
|
|
69
|
+
*
|
|
70
|
+
* @param scope - The scope to run within.
|
|
71
|
+
* @param fn - The function to execute.
|
|
72
|
+
* @returns The return value of the function.
|
|
73
|
+
*/
|
|
74
|
+
declare function runWithScope<T>(scope: Scope, fn: () => T): T;
|
|
75
|
+
/**
|
|
76
|
+
* Dispose a scope and all its children.
|
|
77
|
+
* Children are disposed first (depth-first), then the scope itself.
|
|
78
|
+
*
|
|
79
|
+
* @param scope - The scope to dispose.
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
declare function disposeScope(scope: Scope): void;
|
|
83
|
+
|
|
84
|
+
export { type InjectionKey as I, type Scope as S, createScope as c, disposeScope as d, getActiveScope as g, inject as i, provide as p, runWithScope as r };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';require('@estjs/shared');var r=null,c=0;function d(){return r}function p(e=r){let o={id:++c,parent:e,children:null,provides:null,cleanup:null,onMount:null,onUpdate:null,onDestroy:null,isMounted:false,isDestroyed:false};return e&&(e.children||(e.children=new Set),e.children.add(o)),o}function a(e,o){let l=r;r=e;try{return o()}finally{r=l;}}function i(e){var l;if(!e||e.isDestroyed)return;if(e.isDestroyed=true,e.children&&e.children.size>0){for(let n of e.children)n&&(n.parent=null,i(n));e.children.clear();}let o=r;r=e;try{if(e.onDestroy){for(let n=0;n<e.onDestroy.length;n++)try{e.onDestroy[n]();}catch(t){}e.onDestroy=null;}if(e.cleanup){for(let n=0;n<e.cleanup.length;n++)try{e.cleanup[n]();}catch(t){}e.cleanup=null;}}finally{r=o;}(l=e.parent)!=null&&l.children&&e.parent.children.delete(e),e.provides&&(e.provides.clear(),e.provides=null),e.onMount=null,e.onUpdate=null,e.children=null,e.parent=null;}exports.createScope=p;exports.disposeScope=i;exports.getActiveScope=d;exports.runWithScope=a;//# sourceMappingURL=internal.cjs.js.map
|
|
2
|
+
//# sourceMappingURL=internal.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scope.ts"],"names":["activeScope","scopeId","getActiveScope","createScope","parent","scope","runWithScope","fn","prevScope","disposeScope","_a","child","i","error_"],"mappings":"sCAwCA,IAAIA,CAAAA,CAA4B,IAAA,CAG5BC,EAAU,CAAA,CAOP,SAASC,CAAAA,EAA+B,CAC7C,OAAOF,CACT,CAmBO,SAASG,CAAAA,CAAYC,CAAAA,CAAuBJ,CAAAA,CAAoB,CACrE,IAAMK,EAAe,CACnB,EAAA,CAAI,EAAEJ,CAAAA,CACN,MAAA,CAAAG,CAAAA,CACA,SAAU,IAAA,CACV,QAAA,CAAU,KACV,OAAA,CAAS,IAAA,CACT,QAAS,IAAA,CACT,QAAA,CAAU,IAAA,CACV,SAAA,CAAW,IAAA,CACX,SAAA,CAAW,MACX,WAAA,CAAa,KACf,CAAA,CAGA,OAAIA,CAAAA,GACGA,CAAAA,CAAO,WACVA,CAAAA,CAAO,QAAA,CAAW,IAAI,GAAA,CAAA,CAExBA,CAAAA,CAAO,QAAA,CAAS,IAAIC,CAAK,CAAA,CAAA,CAGpBA,CACT,CAUO,SAASC,EAAgBD,CAAAA,CAAcE,CAAAA,CAAgB,CAC5D,IAAMC,CAAAA,CAAYR,CAAAA,CAClBA,EAAcK,CAAAA,CAEd,GAAI,CACF,OAAOE,CAAAA,EACT,QAAE,CAEAP,CAAAA,CAAcQ,EAChB,CACF,CASO,SAASC,EAAaJ,CAAAA,CAAoB,CA3HjD,IAAAK,CAAAA,CA6HE,GAAI,CAACL,GAASA,CAAAA,CAAM,WAAA,CAClB,OASF,GAJAA,CAAAA,CAAM,WAAA,CAAc,KAIhBA,CAAAA,CAAM,QAAA,EAAYA,CAAAA,CAAM,QAAA,CAAS,IAAA,CAAO,CAAA,CAAG,CAC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import type { InjectionKey } from './provide';\n\n/**\n * Scope represents an execution context in the component tree.\n * It manages provides, cleanup functions, and lifecycle hooks.\n */\nexport interface Scope {\n /** Unique identifier for debugging */\n readonly id: number;\n\n /** Parent scope in the hierarchy */\n parent: Scope | null;\n\n /** Child scopes (lazy initialized) */\n children: Set<Scope> | null;\n\n /** Provided values (lazy initialized) */\n provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;\n\n /** Cleanup functions (lazy initialized) */\n cleanup: Array<() => void> | null;\n\n /** Mount lifecycle hooks (lazy initialized) */\n onMount: Array<() => void | Promise<void>> | null;\n\n /** Update lifecycle hooks (lazy initialized) */\n onUpdate: Array<() => void | Promise<void>> | null;\n\n /** Destroy lifecycle hooks (lazy initialized) */\n onDestroy: Array<() => void | Promise<void>> | null;\n\n /** Whether the scope has been mounted */\n isMounted: boolean;\n\n /** Whether the scope has been destroyed */\n isDestroyed: boolean;\n}\n\n/** Currently active scope */\nlet activeScope: Scope | null = null;\n\n/** Scope ID counter for unique identification */\nlet scopeId = 0;\n\n/**\n * Get the currently active scope.\n *\n * @returns The active scope or null if none is active.\n */\nexport function getActiveScope(): Scope | null {\n return activeScope;\n}\n\n/**\n * Set the active scope (internal use).\n *\n * @param scope - The scope to set as active.\n * @returns {void}\n */\nexport function setActiveScope(scope: Scope | null): void {\n activeScope = scope;\n}\n\n/**\n * Create a new scope with optional parent.\n * If no parent is provided, uses the current active scope as parent.\n *\n * @param parent - Optional parent scope (defaults to active scope).\n * @returns A new scope instance.\n */\nexport function createScope(parent: Scope | null = activeScope): Scope {\n const scope: Scope = {\n id: ++scopeId,\n parent,\n children: null, // Lazy initialized\n provides: null, // Lazy initialized\n cleanup: null, // Lazy initialized\n onMount: null, // Lazy initialized\n onUpdate: null, // Lazy initialized\n onDestroy: null, // Lazy initialized\n isMounted: false,\n isDestroyed: false,\n };\n\n // Establish parent-child relationship\n if (parent) {\n if (!parent.children) {\n parent.children = new Set();\n }\n parent.children.add(scope);\n }\n\n return scope;\n}\n\n/**\n * Run a function within a scope, ensuring proper cleanup.\n * The previous active scope is restored even if the function throws.\n *\n * @param scope - The scope to run within.\n * @param fn - The function to execute.\n * @returns The return value of the function.\n */\nexport function runWithScope<T>(scope: Scope, fn: () => T): T {\n const prevScope = activeScope;\n activeScope = scope;\n\n try {\n return fn();\n } finally {\n // Restore previous scope directly\n activeScope = prevScope;\n }\n}\n\n/**\n * Dispose a scope and all its children.\n * Children are disposed first (depth-first), then the scope itself.\n *\n * @param scope - The scope to dispose.\n * @returns {void}\n */\nexport function disposeScope(scope: Scope): void {\n // Idempotent: already destroyed\n if (!scope || scope.isDestroyed) {\n return;\n }\n\n // Mark destroyed immediately to block re-entrant disposeScope calls\n // (e.g. an onDestroy hook that accidentally disposes the same scope again).\n scope.isDestroyed = true;\n\n // Dispose children first (depth-first)\n // Iterate directly safely by unlinking parent reference to prevent mutation during iteration\n if (scope.children && scope.children.size > 0) {\n for (const child of scope.children) {\n if (child) {\n child.parent = null;\n disposeScope(child);\n }\n }\n scope.children.clear();\n }\n\n // Execute destroy lifecycle hooks and cleanup functions within the scope's\n // context so that inject/provide/getActiveScope work correctly in callbacks.\n //\n // We inline the scope-switching instead of calling `runWithScope()` to avoid\n // an extra function frame on the teardown hot path (disposeScope is called\n // recursively for every child scope in the tree).\n //\n // NOTE: `scope.isDestroyed` is already `true` at this point — this is\n // intentional to prevent re-entrant `disposeScope()` calls from within\n // hooks. Callbacks that inspect `getActiveScope()?.isDestroyed` should\n // be aware of this.\n const prevScope = activeScope;\n activeScope = scope;\n try {\n // Execute destroy lifecycle hooks\n if (scope.onDestroy) {\n for (let i = 0; i < scope.onDestroy.length; i++) {\n try {\n scope.onDestroy[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in destroy hook:`, error_);\n }\n }\n }\n scope.onDestroy = null;\n }\n\n // Execute cleanup functions\n if (scope.cleanup) {\n for (let i = 0; i < scope.cleanup.length; i++) {\n try {\n scope.cleanup[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in cleanup:`, error_);\n }\n }\n }\n scope.cleanup = null;\n }\n } finally {\n activeScope = prevScope;\n }\n\n // Remove from parent's children\n if (scope.parent?.children) {\n scope.parent.children.delete(scope);\n }\n\n // Clear all internal collections to prevent memory leaks\n if (scope.provides) {\n scope.provides.clear();\n scope.provides = null;\n }\n scope.onMount = null;\n scope.onUpdate = null;\n scope.children = null;\n\n // Break parent reference to prevent memory leaks\n scope.parent = null;\n}\n\n/**\n * Register a cleanup function in the current scope.\n * The function will be called when the scope is disposed.\n *\n * @param fn - The cleanup function.\n */\nexport function onCleanup(fn: () => void): void {\n const scope = activeScope;\n\n if (!scope) {\n if (__DEV__) {\n error('onCleanup() must be called within a scope');\n }\n return;\n }\n\n // Lazy initialize cleanup array\n if (!scope.cleanup) {\n scope.cleanup = [];\n }\n\n scope.cleanup.push(fn);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { S as Scope, c as createScope, d as disposeScope, g as getActiveScope, r as runWithScope } from './internal-Bz6h0aPa.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { S as Scope, c as createScope, d as disposeScope, g as getActiveScope, r as runWithScope } from './internal-Bz6h0aPa.js';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var shared = require('@estjs/shared');
|
|
4
|
+
|
|
5
|
+
// src/scope.ts
|
|
6
|
+
var activeScope = null;
|
|
7
|
+
var scopeId = 0;
|
|
8
|
+
function getActiveScope() {
|
|
9
|
+
return activeScope;
|
|
10
|
+
}
|
|
11
|
+
function createScope(parent = activeScope) {
|
|
12
|
+
const scope = {
|
|
13
|
+
id: ++scopeId,
|
|
14
|
+
parent,
|
|
15
|
+
children: null,
|
|
16
|
+
// Lazy initialized
|
|
17
|
+
provides: null,
|
|
18
|
+
// Lazy initialized
|
|
19
|
+
cleanup: null,
|
|
20
|
+
// Lazy initialized
|
|
21
|
+
onMount: null,
|
|
22
|
+
// Lazy initialized
|
|
23
|
+
onUpdate: null,
|
|
24
|
+
// Lazy initialized
|
|
25
|
+
onDestroy: null,
|
|
26
|
+
// Lazy initialized
|
|
27
|
+
isMounted: false,
|
|
28
|
+
isDestroyed: false
|
|
29
|
+
};
|
|
30
|
+
if (parent) {
|
|
31
|
+
if (!parent.children) {
|
|
32
|
+
parent.children = /* @__PURE__ */ new Set();
|
|
33
|
+
}
|
|
34
|
+
parent.children.add(scope);
|
|
35
|
+
}
|
|
36
|
+
return scope;
|
|
37
|
+
}
|
|
38
|
+
function runWithScope(scope, fn) {
|
|
39
|
+
const prevScope = activeScope;
|
|
40
|
+
activeScope = scope;
|
|
41
|
+
try {
|
|
42
|
+
return fn();
|
|
43
|
+
} finally {
|
|
44
|
+
activeScope = prevScope;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function disposeScope(scope) {
|
|
48
|
+
var _a;
|
|
49
|
+
if (!scope || scope.isDestroyed) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
scope.isDestroyed = true;
|
|
53
|
+
if (scope.children && scope.children.size > 0) {
|
|
54
|
+
for (const child of scope.children) {
|
|
55
|
+
if (child) {
|
|
56
|
+
child.parent = null;
|
|
57
|
+
disposeScope(child);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
scope.children.clear();
|
|
61
|
+
}
|
|
62
|
+
const prevScope = activeScope;
|
|
63
|
+
activeScope = scope;
|
|
64
|
+
try {
|
|
65
|
+
if (scope.onDestroy) {
|
|
66
|
+
for (let i = 0; i < scope.onDestroy.length; i++) {
|
|
67
|
+
try {
|
|
68
|
+
scope.onDestroy[i]();
|
|
69
|
+
} catch (error_) {
|
|
70
|
+
if (true) {
|
|
71
|
+
shared.error(`Scope(${scope.id}): Error in destroy hook:`, error_);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
scope.onDestroy = null;
|
|
76
|
+
}
|
|
77
|
+
if (scope.cleanup) {
|
|
78
|
+
for (let i = 0; i < scope.cleanup.length; i++) {
|
|
79
|
+
try {
|
|
80
|
+
scope.cleanup[i]();
|
|
81
|
+
} catch (error_) {
|
|
82
|
+
if (true) {
|
|
83
|
+
shared.error(`Scope(${scope.id}): Error in cleanup:`, error_);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
scope.cleanup = null;
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
activeScope = prevScope;
|
|
91
|
+
}
|
|
92
|
+
if ((_a = scope.parent) == null ? void 0 : _a.children) {
|
|
93
|
+
scope.parent.children.delete(scope);
|
|
94
|
+
}
|
|
95
|
+
if (scope.provides) {
|
|
96
|
+
scope.provides.clear();
|
|
97
|
+
scope.provides = null;
|
|
98
|
+
}
|
|
99
|
+
scope.onMount = null;
|
|
100
|
+
scope.onUpdate = null;
|
|
101
|
+
scope.children = null;
|
|
102
|
+
scope.parent = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.createScope = createScope;
|
|
106
|
+
exports.disposeScope = disposeScope;
|
|
107
|
+
exports.getActiveScope = getActiveScope;
|
|
108
|
+
exports.runWithScope = runWithScope;
|
|
109
|
+
//# sourceMappingURL=internal.dev.cjs.js.map
|
|
110
|
+
//# sourceMappingURL=internal.dev.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scope.ts"],"names":["error"],"mappings":";;;;;AAwCA,IAAI,WAAA,GAA4B,IAAA;AAGhC,IAAI,OAAA,GAAU,CAAA;AAOP,SAAS,cAAA,GAA+B;AAC7C,EAAA,OAAO,WAAA;AACT;AAmBO,SAAS,WAAA,CAAY,SAAuB,WAAA,EAAoB;AACrE,EAAA,MAAM,KAAA,GAAe;AAAA,IACnB,IAAI,EAAE,OAAA;AAAA,IACN,MAAA;AAAA,IACA,QAAA,EAAU,IAAA;AAAA;AAAA,IACV,QAAA,EAAU,IAAA;AA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U;AAClB,IAAA,KAAA,CAAM,SAAS,KAAA,EAAM;AACrB,IAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AAAA,EACnB;AACA,EAAA,KAAA,CAAM,OAAA,GAAU,IAAA;AAChB,EAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AACjB,EAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AAGjB,EAAA,KAAA,CAAM,MAAA,GAAS,IAAA;AACjB","file":"internal.dev.cjs.js","sourcesContent":["import { error } from '@estjs/shared';\nimport type { InjectionKey } from './provide';\n\n/**\n * Scope represents an execution context in the component tree.\n * It manages provides, cleanup functions, and lifecycle hooks.\n */\nexport interface Scope {\n /** Unique identifier for debugging */\n readonly id: number;\n\n /** Parent scope in the hierarchy */\n parent: Scope | null;\n\n /** Child scopes (lazy initialized) */\n children: Set<Scope> | null;\n\n /** Provided values (lazy initialized) */\n provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;\n\n /** Cleanup functions (lazy initialized) */\n cleanup: Array<() => void> | null;\n\n /** Mount lifecycle hooks (lazy initialized) */\n onMount: Array<() => void | Promise<void>> | null;\n\n /** Update lifecycle hooks (lazy initialized) */\n onUpdate: Array<() => void | Promise<void>> | null;\n\n /** Destroy lifecycle hooks (lazy initialized) */\n onDestroy: Array<() => void | Promise<void>> | null;\n\n /** Whether the scope has been mounted */\n isMounted: boolean;\n\n /** Whether the scope has been destroyed */\n isDestroyed: boolean;\n}\n\n/** Currently active scope */\nlet activeScope: Scope | null = null;\n\n/** Scope ID counter for unique identification */\nlet scopeId = 0;\n\n/**\n * Get the currently active scope.\n *\n * @returns The active scope or null if none is active.\n */\nexport function getActiveScope(): Scope | null {\n return activeScope;\n}\n\n/**\n * Set the active scope (internal use).\n *\n * @param scope - The scope to set as active.\n * @returns {void}\n */\nexport function setActiveScope(scope: Scope | null): void {\n activeScope = scope;\n}\n\n/**\n * Create a new scope with optional parent.\n * If no parent is provided, uses the current active scope as parent.\n *\n * @param parent - Optional parent scope (defaults to active scope).\n * @returns A new scope instance.\n */\nexport function createScope(parent: Scope | null = activeScope): Scope {\n const scope: Scope = {\n id: ++scopeId,\n parent,\n children: null, // Lazy initialized\n provides: null, // Lazy initialized\n cleanup: null, // Lazy initialized\n onMount: null, // Lazy initialized\n onUpdate: null, // Lazy initialized\n onDestroy: null, // Lazy initialized\n isMounted: false,\n isDestroyed: false,\n };\n\n // Establish parent-child relationship\n if (parent) {\n if (!parent.children) {\n parent.children = new Set();\n }\n parent.children.add(scope);\n }\n\n return scope;\n}\n\n/**\n * Run a function within a scope, ensuring proper cleanup.\n * The previous active scope is restored even if the function throws.\n *\n * @param scope - The scope to run within.\n * @param fn - The function to execute.\n * @returns The return value of the function.\n */\nexport function runWithScope<T>(scope: Scope, fn: () => T): T {\n const prevScope = activeScope;\n activeScope = scope;\n\n try {\n return fn();\n } finally {\n // Restore previous scope directly\n activeScope = prevScope;\n }\n}\n\n/**\n * Dispose a scope and all its children.\n * Children are disposed first (depth-first), then the scope itself.\n *\n * @param scope - The scope to dispose.\n * @returns {void}\n */\nexport function disposeScope(scope: Scope): void {\n // Idempotent: already destroyed\n if (!scope || scope.isDestroyed) {\n return;\n }\n\n // Mark destroyed immediately to block re-entrant disposeScope calls\n // (e.g. an onDestroy hook that accidentally disposes the same scope again).\n scope.isDestroyed = true;\n\n // Dispose children first (depth-first)\n // Iterate directly safely by unlinking parent reference to prevent mutation during iteration\n if (scope.children && scope.children.size > 0) {\n for (const child of scope.children) {\n if (child) {\n child.parent = null;\n disposeScope(child);\n }\n }\n scope.children.clear();\n }\n\n // Execute destroy lifecycle hooks and cleanup functions within the scope's\n // context so that inject/provide/getActiveScope work correctly in callbacks.\n //\n // We inline the scope-switching instead of calling `runWithScope()` to avoid\n // an extra function frame on the teardown hot path (disposeScope is called\n // recursively for every child scope in the tree).\n //\n // NOTE: `scope.isDestroyed` is already `true` at this point — this is\n // intentional to prevent re-entrant `disposeScope()` calls from within\n // hooks. Callbacks that inspect `getActiveScope()?.isDestroyed` should\n // be aware of this.\n const prevScope = activeScope;\n activeScope = scope;\n try {\n // Execute destroy lifecycle hooks\n if (scope.onDestroy) {\n for (let i = 0; i < scope.onDestroy.length; i++) {\n try {\n scope.onDestroy[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in destroy hook:`, error_);\n }\n }\n }\n scope.onDestroy = null;\n }\n\n // Execute cleanup functions\n if (scope.cleanup) {\n for (let i = 0; i < scope.cleanup.length; i++) {\n try {\n scope.cleanup[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in cleanup:`, error_);\n }\n }\n }\n scope.cleanup = null;\n }\n } finally {\n activeScope = prevScope;\n }\n\n // Remove from parent's children\n if (scope.parent?.children) {\n scope.parent.children.delete(scope);\n }\n\n // Clear all internal collections to prevent memory leaks\n if (scope.provides) {\n scope.provides.clear();\n scope.provides = null;\n }\n scope.onMount = null;\n scope.onUpdate = null;\n scope.children = null;\n\n // Break parent reference to prevent memory leaks\n scope.parent = null;\n}\n\n/**\n * Register a cleanup function in the current scope.\n * The function will be called when the scope is disposed.\n *\n * @param fn - The cleanup function.\n */\nexport function onCleanup(fn: () => void): void {\n const scope = activeScope;\n\n if (!scope) {\n if (__DEV__) {\n error('onCleanup() must be called within a scope');\n }\n return;\n }\n\n // Lazy initialize cleanup array\n if (!scope.cleanup) {\n scope.cleanup = [];\n }\n\n scope.cleanup.push(fn);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"internal.dev.esm.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"internal.esm.js"}
|