@slimlib/store 2.1.0 → 2.2.0
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/index.d.ts +8 -1
- package/index.mjs +5 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -116,7 +116,8 @@ declare module '@slimlib/store' {
|
|
|
116
116
|
* Creates a reactive scope for tracking effects
|
|
117
117
|
* Effects created within a scope callback are automatically tracked and disposed together
|
|
118
118
|
*/
|
|
119
|
-
export const scope: (callback?: ScopeCallback, parent?: Scope | undefined
|
|
119
|
+
export const scope: (callback?: ScopeCallback, parent?: Scope | undefined) => Scope;
|
|
120
|
+
export const getParentScope: (scope: ScopeParent) => ScopeParent | undefined;
|
|
120
121
|
/**
|
|
121
122
|
* Create a simple signal without an initial value
|
|
122
123
|
*/
|
|
@@ -160,6 +161,12 @@ declare module '@slimlib/store' {
|
|
|
160
161
|
export type Scope = ScopeFunction & {
|
|
161
162
|
[key: symbol]: unknown;
|
|
162
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
* A non-disposable reference to a parent scope
|
|
166
|
+
*/
|
|
167
|
+
export type ScopeParent = {
|
|
168
|
+
[key: symbol]: unknown;
|
|
169
|
+
};
|
|
163
170
|
/**
|
|
164
171
|
* Signal type - a callable that returns the current value with a set method
|
|
165
172
|
*/
|
package/index.mjs
CHANGED
|
@@ -12,9 +12,9 @@ const setScheduler = (newScheduler) => {
|
|
|
12
12
|
scheduler = newScheduler;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const [unwrap, propertyDepsSymbol, trackSymbol, childrenSymbol,
|
|
15
|
+
const [unwrap, propertyDepsSymbol, trackSymbol, childrenSymbol, parentSymbol,
|
|
16
16
|
|
|
17
|
-
] = Array.from([, , , ,], Symbol);
|
|
17
|
+
] = Array.from([, , , , ,], Symbol);
|
|
18
18
|
|
|
19
19
|
const noopGetter = () => undefined;
|
|
20
20
|
|
|
@@ -675,6 +675,7 @@ const scope = (callback, parent = activeScope) => {
|
|
|
675
675
|
|
|
676
676
|
ctx[trackSymbol] = (dispose) => effects.push(dispose);
|
|
677
677
|
ctx[childrenSymbol] = children;
|
|
678
|
+
ctx[parentSymbol] = parent;
|
|
678
679
|
|
|
679
680
|
if (parent) {
|
|
680
681
|
myIndex = parent[childrenSymbol].push(ctx) - 1;
|
|
@@ -685,6 +686,7 @@ const scope = (callback, parent = activeScope) => {
|
|
|
685
686
|
}
|
|
686
687
|
return ctx;
|
|
687
688
|
};
|
|
689
|
+
const getParentScope = (scope) => scope[parentSymbol];
|
|
688
690
|
|
|
689
691
|
function signal(initialValue) {
|
|
690
692
|
let value = initialValue;
|
|
@@ -841,4 +843,4 @@ function state(object = {}) {
|
|
|
841
843
|
return createProxy(object);
|
|
842
844
|
}
|
|
843
845
|
|
|
844
|
-
export { EffectOptions, SUPPRESS_EFFECT_GC_WARNING, WARN_ON_UNTRACKED_EFFECT, WARN_ON_WRITE_IN_COMPUTED, activeScope, computed, debugConfig, effect, flushEffects, scope, setActiveScope, setScheduler, signal, state, untracked, unwrapValue };
|
|
846
|
+
export { EffectOptions, SUPPRESS_EFFECT_GC_WARNING, WARN_ON_UNTRACKED_EFFECT, WARN_ON_WRITE_IN_COMPUTED, activeScope, computed, debugConfig, effect, flushEffects, getParentScope, scope, setActiveScope, setScheduler, signal, state, untracked, unwrapValue };
|