@estjs/signals 0.0.16-beta.2 → 0.0.16-beta.3
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/signals.cjs.js +3 -3
- package/dist/signals.cjs.js.map +1 -1
- package/dist/signals.d.cts +36 -183
- package/dist/signals.d.ts +36 -183
- package/dist/signals.dev.cjs.js +243 -95
- package/dist/signals.dev.esm.js +239 -96
- package/dist/signals.esm.js +3 -3
- package/dist/signals.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/signals.d.cts
CHANGED
|
@@ -84,215 +84,35 @@ declare enum SignalFlags {
|
|
|
84
84
|
IS_EFFECT = "_IS_EFFECT"
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/**
|
|
88
|
-
* Link - Bidirectional connection in the dependency graph
|
|
89
|
-
*
|
|
90
|
-
* A Link connects two ReactiveNodes:
|
|
91
|
-
* - depNode: The dependency node (data source)
|
|
92
|
-
* - subNode: The subscriber node (data consumer)
|
|
93
|
-
*
|
|
94
|
-
* Links form doubly-linked lists in two directions:
|
|
95
|
-
* 1. Subscriber Chain: Connects all subscribers of the same dependency
|
|
96
|
-
* 2. Dependency Chain: Connects all dependencies of the same subscriber
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```
|
|
100
|
-
* Signal A ←─┐
|
|
101
|
-
* ├─→ Effect X
|
|
102
|
-
* Signal B ←─┘
|
|
103
|
-
*
|
|
104
|
-
* Link1: A → X (A's subscriber chain, X's dependency chain)
|
|
105
|
-
* Link2: B → X (B's subscriber chain, X's dependency chain)
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
87
|
interface Link {
|
|
109
|
-
/**
|
|
110
|
-
* Version number
|
|
111
|
-
*
|
|
112
|
-
* Used to detect stale Links.
|
|
113
|
-
* The global version number increments each time dependency tracking starts.
|
|
114
|
-
* Links with old versions will be cleaned up.
|
|
115
|
-
*
|
|
116
|
-
*/
|
|
117
88
|
version: number;
|
|
118
|
-
/**
|
|
119
|
-
* Dependency node - The data source being depended on
|
|
120
|
-
* Examples: Signal, Computed
|
|
121
|
-
*/
|
|
122
89
|
depNode: ReactiveNode;
|
|
123
|
-
/**
|
|
124
|
-
* Subscriber node - The consumer of the data
|
|
125
|
-
* Examples: Effect, Computed
|
|
126
|
-
*/
|
|
127
90
|
subNode: ReactiveNode;
|
|
128
|
-
/** Previous subscriber Link */
|
|
129
91
|
prevSubLink?: Link;
|
|
130
|
-
/** Next subscriber Link */
|
|
131
92
|
nextSubLink?: Link;
|
|
132
|
-
/** Previous dependency Link */
|
|
133
93
|
prevDepLink?: Link;
|
|
134
|
-
/** Next dependency Link */
|
|
135
94
|
nextDepLink?: Link;
|
|
136
95
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Debugger event types for tracking reactive operations
|
|
139
|
-
*/
|
|
140
96
|
type DebuggerEventType = 'get' | 'set' | 'add' | 'delete' | 'clear' | 'iterate';
|
|
141
|
-
/**
|
|
142
|
-
* Debugger event for tracking reactive operations
|
|
143
|
-
*
|
|
144
|
-
* This event is passed to onTrack and onTrigger callbacks to provide
|
|
145
|
-
* detailed information about reactive operations for debugging purposes.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* effect(() => {
|
|
150
|
-
* console.log(signal.value);
|
|
151
|
-
* }, {
|
|
152
|
-
* onTrack(event) {
|
|
153
|
-
* console.log('Tracked:', event.type, event.key);
|
|
154
|
-
* },
|
|
155
|
-
* onTrigger(event) {
|
|
156
|
-
* console.log('Triggered:', event.type, event.key, event.newValue);
|
|
157
|
-
* }
|
|
158
|
-
* });
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
97
|
interface DebuggerEvent {
|
|
162
|
-
/** The effect or computed that is tracking/being triggered */
|
|
163
98
|
effect: ReactiveNode;
|
|
164
|
-
/** The reactive object being accessed or modified */
|
|
165
99
|
target: object;
|
|
166
|
-
/** The type of operation */
|
|
167
100
|
type: DebuggerEventType | string;
|
|
168
|
-
/** The property key being accessed or modified (optional) */
|
|
169
101
|
key?: any;
|
|
170
|
-
/** The new value being set (optional, only for trigger events) */
|
|
171
102
|
newValue?: any;
|
|
172
103
|
}
|
|
173
|
-
/**
|
|
174
|
-
* ReactiveNode - Reactive node interface
|
|
175
|
-
*
|
|
176
|
-
* All objects participating in the reactive system implement this interface.
|
|
177
|
-
* Includes Signal, Computed, Effect, Reactive objects, etc.
|
|
178
|
-
*
|
|
179
|
-
* Nodes form a dependency graph through Links:
|
|
180
|
-
* - depLink: List of nodes I depend on
|
|
181
|
-
* - subLink: List of nodes that depend on me
|
|
182
|
-
*/
|
|
183
104
|
interface ReactiveNode {
|
|
184
|
-
/**
|
|
185
|
-
* Dependency chain head - The first node I depend on
|
|
186
|
-
*
|
|
187
|
-
* Traverse all dependencies through nextDepLink.
|
|
188
|
-
*/
|
|
189
105
|
depLink?: Link;
|
|
190
|
-
/**
|
|
191
|
-
* Subscriber chain head - The first node that depends on me
|
|
192
|
-
*
|
|
193
|
-
* Traverse all subscribers through nextSubLink.
|
|
194
|
-
*/
|
|
195
106
|
subLink?: Link;
|
|
196
|
-
/**
|
|
197
|
-
* Dependency chain tail - The last node I depend on
|
|
198
|
-
*
|
|
199
|
-
* Used for O(1) time complexity linked list append operations.
|
|
200
|
-
*/
|
|
201
107
|
depLinkTail?: Link;
|
|
202
|
-
/**
|
|
203
|
-
* Subscriber chain tail - The last node that depends on me
|
|
204
|
-
*
|
|
205
|
-
* Used for O(1) time complexity linked list append operations.
|
|
206
|
-
*/
|
|
207
108
|
subLinkTail?: Link;
|
|
208
|
-
/**
|
|
209
|
-
* State flags
|
|
210
|
-
* @see ReactiveFlags
|
|
211
|
-
*/
|
|
212
109
|
flag: ReactiveFlags;
|
|
213
|
-
/**
|
|
214
|
-
* Optional debugging hook called when dependencies are tracked
|
|
215
|
-
*/
|
|
216
110
|
onTrack?: (event: DebuggerEvent) => void;
|
|
217
|
-
/**
|
|
218
|
-
* Optional debugging hook called when reactive changes are triggered.
|
|
219
|
-
*/
|
|
220
111
|
onTrigger?: (event: DebuggerEvent) => void;
|
|
221
|
-
/**
|
|
222
|
-
* When true, this node is a pure dependency (leaf); it should not receive
|
|
223
|
-
* a DIRTY flag during invalidation because it has no derived value to recompute.
|
|
224
|
-
*/
|
|
225
112
|
isDep?: boolean;
|
|
226
|
-
/**
|
|
227
|
-
* Deduplication stamp used during batch notification.
|
|
228
|
-
* Prevents the same effect from being pushed into the pending queue twice.
|
|
229
|
-
*/
|
|
230
113
|
_triggerVersion?: number;
|
|
231
114
|
}
|
|
232
|
-
/**
|
|
233
|
-
* Execute function with tracking disabled.
|
|
234
|
-
*
|
|
235
|
-
* @param fn - The function to execute.
|
|
236
|
-
* @returns {T} The function's return value.
|
|
237
|
-
*/
|
|
238
115
|
declare function untrack<T>(fn: () => T): T;
|
|
239
|
-
/**
|
|
240
|
-
* Trigger updates for subscribers of a reactive object property.
|
|
241
|
-
*
|
|
242
|
-
* This function notifies all subscribers (effects/computed) that depend on a specific
|
|
243
|
-
* property of a reactive object that the property has changed.
|
|
244
|
-
*
|
|
245
|
-
* ## When is this called?
|
|
246
|
-
*
|
|
247
|
-
* - When setting a property: `reactiveObj.prop = value` → trigger(obj, 'SET', 'prop', value)
|
|
248
|
-
* - When adding a property: `reactiveObj.newProp = value` → trigger(obj, 'ADD', 'newProp', value)
|
|
249
|
-
* - When deleting a property: `delete reactiveObj.prop` → trigger(obj, 'DELETE', 'prop')
|
|
250
|
-
* - When clearing a collection: `reactiveArray.length = 0` → trigger(obj, 'CLEAR')
|
|
251
|
-
* - When mutating arrays: `reactiveArray.push(item)` → trigger(obj, 'SET', 'length', newLength)
|
|
252
|
-
*
|
|
253
|
-
* ## Operation Types
|
|
254
|
-
*
|
|
255
|
-
* - **SET**: Property value changed (most common)
|
|
256
|
-
* - **ADD**: New property added (affects iteration)
|
|
257
|
-
* - **DELETE**: Property removed (affects iteration)
|
|
258
|
-
* - **CLEAR**: Collection cleared (affects iteration)
|
|
259
|
-
*
|
|
260
|
-
* ## Iteration Dependencies
|
|
261
|
-
*
|
|
262
|
-
* @param target - The reactive object that changed.
|
|
263
|
-
* @param type - The type of operation: 'SET' | 'ADD' | 'DELETE' | 'CLEAR'.
|
|
264
|
-
* @param key - The property key that changed (optional for CLEAR operations).
|
|
265
|
-
* @param newValue - The new value.
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* ```typescript
|
|
269
|
-
* const state = reactive({ count: 0, items: [1, 2, 3] });
|
|
270
|
-
*
|
|
271
|
-
* effect(() => {
|
|
272
|
-
* console.log(state.count); // Depends on 'count'
|
|
273
|
-
* });
|
|
274
|
-
*
|
|
275
|
-
* effect(() => {
|
|
276
|
-
* console.log(state.items.length); // Depends on 'items' and iteration
|
|
277
|
-
* });
|
|
278
|
-
*
|
|
279
|
-
* // Triggers first effect only
|
|
280
|
-
* state.count = 1; // trigger(state, 'SET', 'count', 1)
|
|
281
|
-
*
|
|
282
|
-
* // Triggers second effect (changes length and iteration)
|
|
283
|
-
* state.items.push(4); // trigger(state.items, 'SET', 'length', 4)
|
|
284
|
-
* // trigger(state.items, 'ADD', '3', 4)
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
/**
|
|
288
|
-
* Trigger updates for subscribers of a reactive object property.
|
|
289
|
-
*
|
|
290
|
-
* @param target - The reactive object that changed.
|
|
291
|
-
* @param type - The type of operation: 'SET' | 'ADD' | 'DELETE' | 'CLEAR'.
|
|
292
|
-
* @param key - The property key that changed (optional for CLEAR operations).
|
|
293
|
-
* @param newValue - The new value.
|
|
294
|
-
* @returns {void}
|
|
295
|
-
*/
|
|
296
116
|
declare function trigger(target: object, type: string, key?: string | symbol | (string | symbol)[], newValue?: unknown): void;
|
|
297
117
|
|
|
298
118
|
/**
|
|
@@ -390,6 +210,34 @@ declare function shallowSignal<T>(value?: T): Signal<T>;
|
|
|
390
210
|
*/
|
|
391
211
|
declare function isSignal<T>(value: unknown): value is Signal<T>;
|
|
392
212
|
|
|
213
|
+
interface ScopedReactiveEffect {
|
|
214
|
+
stop(): void;
|
|
215
|
+
pause?(): void;
|
|
216
|
+
resume?(): void;
|
|
217
|
+
scope?: EffectScope;
|
|
218
|
+
}
|
|
219
|
+
declare class EffectScope {
|
|
220
|
+
detached: boolean;
|
|
221
|
+
parent: EffectScope | undefined;
|
|
222
|
+
private _active;
|
|
223
|
+
private effects;
|
|
224
|
+
private scopes;
|
|
225
|
+
private cleanups;
|
|
226
|
+
constructor(detached?: boolean, parent?: EffectScope | undefined);
|
|
227
|
+
get active(): boolean;
|
|
228
|
+
pause(): void;
|
|
229
|
+
resume(): void;
|
|
230
|
+
run<T>(fn: () => T): T | undefined;
|
|
231
|
+
stop(fromParent?: boolean): void;
|
|
232
|
+
_record(effect: ScopedReactiveEffect): void;
|
|
233
|
+
_remove(effect: ScopedReactiveEffect): void;
|
|
234
|
+
_pushCleanup(fn: () => void): void;
|
|
235
|
+
}
|
|
236
|
+
declare function effectScope(detached?: boolean): EffectScope;
|
|
237
|
+
declare function getCurrentScope(): EffectScope | undefined;
|
|
238
|
+
declare function setCurrentScope(scope?: EffectScope): EffectScope | undefined;
|
|
239
|
+
declare function onScopeDispose(fn: () => void, failSilently?: boolean): void;
|
|
240
|
+
|
|
393
241
|
/**
|
|
394
242
|
* Computed getter function type
|
|
395
243
|
*/
|
|
@@ -453,7 +301,7 @@ type ComputedType<T> = T extends Computed<infer V> ? V : never;
|
|
|
453
301
|
*
|
|
454
302
|
* @template T - The type of the computed value
|
|
455
303
|
*/
|
|
456
|
-
declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
304
|
+
declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode, ScopedReactiveEffect {
|
|
457
305
|
depLink?: Link;
|
|
458
306
|
subLink?: Link;
|
|
459
307
|
depLinkTail?: Link;
|
|
@@ -464,7 +312,9 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
464
312
|
readonly setter?: ComputedSetter<T>;
|
|
465
313
|
readonly onTrack?: (event: DebuggerEvent) => void;
|
|
466
314
|
readonly onTrigger?: (event: DebuggerEvent) => void;
|
|
315
|
+
scope?: EffectScope;
|
|
467
316
|
private _value;
|
|
317
|
+
private _active;
|
|
468
318
|
/**
|
|
469
319
|
* Create a Computed instance.
|
|
470
320
|
*
|
|
@@ -492,6 +342,7 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
492
342
|
* @returns {T} The current value.
|
|
493
343
|
*/
|
|
494
344
|
peek(): T;
|
|
345
|
+
get active(): boolean;
|
|
495
346
|
/**
|
|
496
347
|
* Recompute the value
|
|
497
348
|
*
|
|
@@ -512,6 +363,7 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
512
363
|
* @returns {boolean} True if value changed.
|
|
513
364
|
*/
|
|
514
365
|
shouldUpdate(): boolean;
|
|
366
|
+
stop(): void;
|
|
515
367
|
}
|
|
516
368
|
/**
|
|
517
369
|
* Create a Computed value.
|
|
@@ -757,7 +609,7 @@ interface EffectRunner<T = any> {
|
|
|
757
609
|
*
|
|
758
610
|
* @template T - The return type of the effect function
|
|
759
611
|
*/
|
|
760
|
-
declare class EffectImpl<T = any> implements ReactiveNode {
|
|
612
|
+
declare class EffectImpl<T = any> implements ReactiveNode, ScopedReactiveEffect {
|
|
761
613
|
depLink?: Link;
|
|
762
614
|
subLink?: Link;
|
|
763
615
|
depLinkTail?: Link;
|
|
@@ -770,6 +622,7 @@ declare class EffectImpl<T = any> implements ReactiveNode {
|
|
|
770
622
|
onTrack?: (event: DebuggerEvent) => void;
|
|
771
623
|
onTrigger?: (event: DebuggerEvent) => void;
|
|
772
624
|
private _active;
|
|
625
|
+
scope?: EffectScope;
|
|
773
626
|
/**
|
|
774
627
|
* Create an Effect instance.
|
|
775
628
|
*
|
|
@@ -1204,4 +1057,4 @@ type WatchCallback<T = any> = (newValue: T, oldValue: T | undefined) => void;
|
|
|
1204
1057
|
*/
|
|
1205
1058
|
declare function watch<T = any>(source: WatchSource<T>, callback: WatchCallback<T>, options?: WatchOptions): () => void;
|
|
1206
1059
|
|
|
1207
|
-
export { type Computed, type ComputedGetter, type ComputedOptions, type ComputedSetter, type ComputedType, type DebuggerEvent, type DebuggerEventType, type EffectFunction, type EffectOptions, type EffectRunner, type EffectScheduler, type FlushTiming, type Job, type MemoEffectFn, type PreFlushCallback, type Reactive, type Ref, type Signal, type SignalType, type SignalValue, type StoreActions, type StoreOptions, TriggerOpTypes, type Unwrap, batch, computed, createStore, effect, endBatch, getBatchDepth, isBatching, isComputed, isEffect, isReactive, isRef, isShallow, isSignal, memoEffect, nextTick, queueJob, queuePreFlushCb, reactive, ref, shallowReactive, shallowSignal, signal, startBatch, stop, toRaw, toReactive, trigger, untrack, watch };
|
|
1060
|
+
export { type Computed, type ComputedGetter, type ComputedOptions, type ComputedSetter, type ComputedType, type DebuggerEvent, type DebuggerEventType, type EffectFunction, type EffectOptions, type EffectRunner, type EffectScheduler, EffectScope, type FlushTiming, type Job, type MemoEffectFn, type PreFlushCallback, type Reactive, type Ref, type Signal, type SignalType, type SignalValue, type StoreActions, type StoreOptions, TriggerOpTypes, type Unwrap, batch, computed, createStore, effect, effectScope, endBatch, getBatchDepth, getCurrentScope, isBatching, isComputed, isEffect, isReactive, isRef, isShallow, isSignal, memoEffect, nextTick, onScopeDispose, queueJob, queuePreFlushCb, reactive, ref, setCurrentScope, shallowReactive, shallowSignal, signal, startBatch, stop, toRaw, toReactive, trigger, untrack, watch };
|
package/dist/signals.d.ts
CHANGED
|
@@ -84,215 +84,35 @@ declare enum SignalFlags {
|
|
|
84
84
|
IS_EFFECT = "_IS_EFFECT"
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/**
|
|
88
|
-
* Link - Bidirectional connection in the dependency graph
|
|
89
|
-
*
|
|
90
|
-
* A Link connects two ReactiveNodes:
|
|
91
|
-
* - depNode: The dependency node (data source)
|
|
92
|
-
* - subNode: The subscriber node (data consumer)
|
|
93
|
-
*
|
|
94
|
-
* Links form doubly-linked lists in two directions:
|
|
95
|
-
* 1. Subscriber Chain: Connects all subscribers of the same dependency
|
|
96
|
-
* 2. Dependency Chain: Connects all dependencies of the same subscriber
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```
|
|
100
|
-
* Signal A ←─┐
|
|
101
|
-
* ├─→ Effect X
|
|
102
|
-
* Signal B ←─┘
|
|
103
|
-
*
|
|
104
|
-
* Link1: A → X (A's subscriber chain, X's dependency chain)
|
|
105
|
-
* Link2: B → X (B's subscriber chain, X's dependency chain)
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
87
|
interface Link {
|
|
109
|
-
/**
|
|
110
|
-
* Version number
|
|
111
|
-
*
|
|
112
|
-
* Used to detect stale Links.
|
|
113
|
-
* The global version number increments each time dependency tracking starts.
|
|
114
|
-
* Links with old versions will be cleaned up.
|
|
115
|
-
*
|
|
116
|
-
*/
|
|
117
88
|
version: number;
|
|
118
|
-
/**
|
|
119
|
-
* Dependency node - The data source being depended on
|
|
120
|
-
* Examples: Signal, Computed
|
|
121
|
-
*/
|
|
122
89
|
depNode: ReactiveNode;
|
|
123
|
-
/**
|
|
124
|
-
* Subscriber node - The consumer of the data
|
|
125
|
-
* Examples: Effect, Computed
|
|
126
|
-
*/
|
|
127
90
|
subNode: ReactiveNode;
|
|
128
|
-
/** Previous subscriber Link */
|
|
129
91
|
prevSubLink?: Link;
|
|
130
|
-
/** Next subscriber Link */
|
|
131
92
|
nextSubLink?: Link;
|
|
132
|
-
/** Previous dependency Link */
|
|
133
93
|
prevDepLink?: Link;
|
|
134
|
-
/** Next dependency Link */
|
|
135
94
|
nextDepLink?: Link;
|
|
136
95
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Debugger event types for tracking reactive operations
|
|
139
|
-
*/
|
|
140
96
|
type DebuggerEventType = 'get' | 'set' | 'add' | 'delete' | 'clear' | 'iterate';
|
|
141
|
-
/**
|
|
142
|
-
* Debugger event for tracking reactive operations
|
|
143
|
-
*
|
|
144
|
-
* This event is passed to onTrack and onTrigger callbacks to provide
|
|
145
|
-
* detailed information about reactive operations for debugging purposes.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* effect(() => {
|
|
150
|
-
* console.log(signal.value);
|
|
151
|
-
* }, {
|
|
152
|
-
* onTrack(event) {
|
|
153
|
-
* console.log('Tracked:', event.type, event.key);
|
|
154
|
-
* },
|
|
155
|
-
* onTrigger(event) {
|
|
156
|
-
* console.log('Triggered:', event.type, event.key, event.newValue);
|
|
157
|
-
* }
|
|
158
|
-
* });
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
97
|
interface DebuggerEvent {
|
|
162
|
-
/** The effect or computed that is tracking/being triggered */
|
|
163
98
|
effect: ReactiveNode;
|
|
164
|
-
/** The reactive object being accessed or modified */
|
|
165
99
|
target: object;
|
|
166
|
-
/** The type of operation */
|
|
167
100
|
type: DebuggerEventType | string;
|
|
168
|
-
/** The property key being accessed or modified (optional) */
|
|
169
101
|
key?: any;
|
|
170
|
-
/** The new value being set (optional, only for trigger events) */
|
|
171
102
|
newValue?: any;
|
|
172
103
|
}
|
|
173
|
-
/**
|
|
174
|
-
* ReactiveNode - Reactive node interface
|
|
175
|
-
*
|
|
176
|
-
* All objects participating in the reactive system implement this interface.
|
|
177
|
-
* Includes Signal, Computed, Effect, Reactive objects, etc.
|
|
178
|
-
*
|
|
179
|
-
* Nodes form a dependency graph through Links:
|
|
180
|
-
* - depLink: List of nodes I depend on
|
|
181
|
-
* - subLink: List of nodes that depend on me
|
|
182
|
-
*/
|
|
183
104
|
interface ReactiveNode {
|
|
184
|
-
/**
|
|
185
|
-
* Dependency chain head - The first node I depend on
|
|
186
|
-
*
|
|
187
|
-
* Traverse all dependencies through nextDepLink.
|
|
188
|
-
*/
|
|
189
105
|
depLink?: Link;
|
|
190
|
-
/**
|
|
191
|
-
* Subscriber chain head - The first node that depends on me
|
|
192
|
-
*
|
|
193
|
-
* Traverse all subscribers through nextSubLink.
|
|
194
|
-
*/
|
|
195
106
|
subLink?: Link;
|
|
196
|
-
/**
|
|
197
|
-
* Dependency chain tail - The last node I depend on
|
|
198
|
-
*
|
|
199
|
-
* Used for O(1) time complexity linked list append operations.
|
|
200
|
-
*/
|
|
201
107
|
depLinkTail?: Link;
|
|
202
|
-
/**
|
|
203
|
-
* Subscriber chain tail - The last node that depends on me
|
|
204
|
-
*
|
|
205
|
-
* Used for O(1) time complexity linked list append operations.
|
|
206
|
-
*/
|
|
207
108
|
subLinkTail?: Link;
|
|
208
|
-
/**
|
|
209
|
-
* State flags
|
|
210
|
-
* @see ReactiveFlags
|
|
211
|
-
*/
|
|
212
109
|
flag: ReactiveFlags;
|
|
213
|
-
/**
|
|
214
|
-
* Optional debugging hook called when dependencies are tracked
|
|
215
|
-
*/
|
|
216
110
|
onTrack?: (event: DebuggerEvent) => void;
|
|
217
|
-
/**
|
|
218
|
-
* Optional debugging hook called when reactive changes are triggered.
|
|
219
|
-
*/
|
|
220
111
|
onTrigger?: (event: DebuggerEvent) => void;
|
|
221
|
-
/**
|
|
222
|
-
* When true, this node is a pure dependency (leaf); it should not receive
|
|
223
|
-
* a DIRTY flag during invalidation because it has no derived value to recompute.
|
|
224
|
-
*/
|
|
225
112
|
isDep?: boolean;
|
|
226
|
-
/**
|
|
227
|
-
* Deduplication stamp used during batch notification.
|
|
228
|
-
* Prevents the same effect from being pushed into the pending queue twice.
|
|
229
|
-
*/
|
|
230
113
|
_triggerVersion?: number;
|
|
231
114
|
}
|
|
232
|
-
/**
|
|
233
|
-
* Execute function with tracking disabled.
|
|
234
|
-
*
|
|
235
|
-
* @param fn - The function to execute.
|
|
236
|
-
* @returns {T} The function's return value.
|
|
237
|
-
*/
|
|
238
115
|
declare function untrack<T>(fn: () => T): T;
|
|
239
|
-
/**
|
|
240
|
-
* Trigger updates for subscribers of a reactive object property.
|
|
241
|
-
*
|
|
242
|
-
* This function notifies all subscribers (effects/computed) that depend on a specific
|
|
243
|
-
* property of a reactive object that the property has changed.
|
|
244
|
-
*
|
|
245
|
-
* ## When is this called?
|
|
246
|
-
*
|
|
247
|
-
* - When setting a property: `reactiveObj.prop = value` → trigger(obj, 'SET', 'prop', value)
|
|
248
|
-
* - When adding a property: `reactiveObj.newProp = value` → trigger(obj, 'ADD', 'newProp', value)
|
|
249
|
-
* - When deleting a property: `delete reactiveObj.prop` → trigger(obj, 'DELETE', 'prop')
|
|
250
|
-
* - When clearing a collection: `reactiveArray.length = 0` → trigger(obj, 'CLEAR')
|
|
251
|
-
* - When mutating arrays: `reactiveArray.push(item)` → trigger(obj, 'SET', 'length', newLength)
|
|
252
|
-
*
|
|
253
|
-
* ## Operation Types
|
|
254
|
-
*
|
|
255
|
-
* - **SET**: Property value changed (most common)
|
|
256
|
-
* - **ADD**: New property added (affects iteration)
|
|
257
|
-
* - **DELETE**: Property removed (affects iteration)
|
|
258
|
-
* - **CLEAR**: Collection cleared (affects iteration)
|
|
259
|
-
*
|
|
260
|
-
* ## Iteration Dependencies
|
|
261
|
-
*
|
|
262
|
-
* @param target - The reactive object that changed.
|
|
263
|
-
* @param type - The type of operation: 'SET' | 'ADD' | 'DELETE' | 'CLEAR'.
|
|
264
|
-
* @param key - The property key that changed (optional for CLEAR operations).
|
|
265
|
-
* @param newValue - The new value.
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* ```typescript
|
|
269
|
-
* const state = reactive({ count: 0, items: [1, 2, 3] });
|
|
270
|
-
*
|
|
271
|
-
* effect(() => {
|
|
272
|
-
* console.log(state.count); // Depends on 'count'
|
|
273
|
-
* });
|
|
274
|
-
*
|
|
275
|
-
* effect(() => {
|
|
276
|
-
* console.log(state.items.length); // Depends on 'items' and iteration
|
|
277
|
-
* });
|
|
278
|
-
*
|
|
279
|
-
* // Triggers first effect only
|
|
280
|
-
* state.count = 1; // trigger(state, 'SET', 'count', 1)
|
|
281
|
-
*
|
|
282
|
-
* // Triggers second effect (changes length and iteration)
|
|
283
|
-
* state.items.push(4); // trigger(state.items, 'SET', 'length', 4)
|
|
284
|
-
* // trigger(state.items, 'ADD', '3', 4)
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
/**
|
|
288
|
-
* Trigger updates for subscribers of a reactive object property.
|
|
289
|
-
*
|
|
290
|
-
* @param target - The reactive object that changed.
|
|
291
|
-
* @param type - The type of operation: 'SET' | 'ADD' | 'DELETE' | 'CLEAR'.
|
|
292
|
-
* @param key - The property key that changed (optional for CLEAR operations).
|
|
293
|
-
* @param newValue - The new value.
|
|
294
|
-
* @returns {void}
|
|
295
|
-
*/
|
|
296
116
|
declare function trigger(target: object, type: string, key?: string | symbol | (string | symbol)[], newValue?: unknown): void;
|
|
297
117
|
|
|
298
118
|
/**
|
|
@@ -390,6 +210,34 @@ declare function shallowSignal<T>(value?: T): Signal<T>;
|
|
|
390
210
|
*/
|
|
391
211
|
declare function isSignal<T>(value: unknown): value is Signal<T>;
|
|
392
212
|
|
|
213
|
+
interface ScopedReactiveEffect {
|
|
214
|
+
stop(): void;
|
|
215
|
+
pause?(): void;
|
|
216
|
+
resume?(): void;
|
|
217
|
+
scope?: EffectScope;
|
|
218
|
+
}
|
|
219
|
+
declare class EffectScope {
|
|
220
|
+
detached: boolean;
|
|
221
|
+
parent: EffectScope | undefined;
|
|
222
|
+
private _active;
|
|
223
|
+
private effects;
|
|
224
|
+
private scopes;
|
|
225
|
+
private cleanups;
|
|
226
|
+
constructor(detached?: boolean, parent?: EffectScope | undefined);
|
|
227
|
+
get active(): boolean;
|
|
228
|
+
pause(): void;
|
|
229
|
+
resume(): void;
|
|
230
|
+
run<T>(fn: () => T): T | undefined;
|
|
231
|
+
stop(fromParent?: boolean): void;
|
|
232
|
+
_record(effect: ScopedReactiveEffect): void;
|
|
233
|
+
_remove(effect: ScopedReactiveEffect): void;
|
|
234
|
+
_pushCleanup(fn: () => void): void;
|
|
235
|
+
}
|
|
236
|
+
declare function effectScope(detached?: boolean): EffectScope;
|
|
237
|
+
declare function getCurrentScope(): EffectScope | undefined;
|
|
238
|
+
declare function setCurrentScope(scope?: EffectScope): EffectScope | undefined;
|
|
239
|
+
declare function onScopeDispose(fn: () => void, failSilently?: boolean): void;
|
|
240
|
+
|
|
393
241
|
/**
|
|
394
242
|
* Computed getter function type
|
|
395
243
|
*/
|
|
@@ -453,7 +301,7 @@ type ComputedType<T> = T extends Computed<infer V> ? V : never;
|
|
|
453
301
|
*
|
|
454
302
|
* @template T - The type of the computed value
|
|
455
303
|
*/
|
|
456
|
-
declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
304
|
+
declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode, ScopedReactiveEffect {
|
|
457
305
|
depLink?: Link;
|
|
458
306
|
subLink?: Link;
|
|
459
307
|
depLinkTail?: Link;
|
|
@@ -464,7 +312,9 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
464
312
|
readonly setter?: ComputedSetter<T>;
|
|
465
313
|
readonly onTrack?: (event: DebuggerEvent) => void;
|
|
466
314
|
readonly onTrigger?: (event: DebuggerEvent) => void;
|
|
315
|
+
scope?: EffectScope;
|
|
467
316
|
private _value;
|
|
317
|
+
private _active;
|
|
468
318
|
/**
|
|
469
319
|
* Create a Computed instance.
|
|
470
320
|
*
|
|
@@ -492,6 +342,7 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
492
342
|
* @returns {T} The current value.
|
|
493
343
|
*/
|
|
494
344
|
peek(): T;
|
|
345
|
+
get active(): boolean;
|
|
495
346
|
/**
|
|
496
347
|
* Recompute the value
|
|
497
348
|
*
|
|
@@ -512,6 +363,7 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
512
363
|
* @returns {boolean} True if value changed.
|
|
513
364
|
*/
|
|
514
365
|
shouldUpdate(): boolean;
|
|
366
|
+
stop(): void;
|
|
515
367
|
}
|
|
516
368
|
/**
|
|
517
369
|
* Create a Computed value.
|
|
@@ -757,7 +609,7 @@ interface EffectRunner<T = any> {
|
|
|
757
609
|
*
|
|
758
610
|
* @template T - The return type of the effect function
|
|
759
611
|
*/
|
|
760
|
-
declare class EffectImpl<T = any> implements ReactiveNode {
|
|
612
|
+
declare class EffectImpl<T = any> implements ReactiveNode, ScopedReactiveEffect {
|
|
761
613
|
depLink?: Link;
|
|
762
614
|
subLink?: Link;
|
|
763
615
|
depLinkTail?: Link;
|
|
@@ -770,6 +622,7 @@ declare class EffectImpl<T = any> implements ReactiveNode {
|
|
|
770
622
|
onTrack?: (event: DebuggerEvent) => void;
|
|
771
623
|
onTrigger?: (event: DebuggerEvent) => void;
|
|
772
624
|
private _active;
|
|
625
|
+
scope?: EffectScope;
|
|
773
626
|
/**
|
|
774
627
|
* Create an Effect instance.
|
|
775
628
|
*
|
|
@@ -1204,4 +1057,4 @@ type WatchCallback<T = any> = (newValue: T, oldValue: T | undefined) => void;
|
|
|
1204
1057
|
*/
|
|
1205
1058
|
declare function watch<T = any>(source: WatchSource<T>, callback: WatchCallback<T>, options?: WatchOptions): () => void;
|
|
1206
1059
|
|
|
1207
|
-
export { type Computed, type ComputedGetter, type ComputedOptions, type ComputedSetter, type ComputedType, type DebuggerEvent, type DebuggerEventType, type EffectFunction, type EffectOptions, type EffectRunner, type EffectScheduler, type FlushTiming, type Job, type MemoEffectFn, type PreFlushCallback, type Reactive, type Ref, type Signal, type SignalType, type SignalValue, type StoreActions, type StoreOptions, TriggerOpTypes, type Unwrap, batch, computed, createStore, effect, endBatch, getBatchDepth, isBatching, isComputed, isEffect, isReactive, isRef, isShallow, isSignal, memoEffect, nextTick, queueJob, queuePreFlushCb, reactive, ref, shallowReactive, shallowSignal, signal, startBatch, stop, toRaw, toReactive, trigger, untrack, watch };
|
|
1060
|
+
export { type Computed, type ComputedGetter, type ComputedOptions, type ComputedSetter, type ComputedType, type DebuggerEvent, type DebuggerEventType, type EffectFunction, type EffectOptions, type EffectRunner, type EffectScheduler, EffectScope, type FlushTiming, type Job, type MemoEffectFn, type PreFlushCallback, type Reactive, type Ref, type Signal, type SignalType, type SignalValue, type StoreActions, type StoreOptions, TriggerOpTypes, type Unwrap, batch, computed, createStore, effect, effectScope, endBatch, getBatchDepth, getCurrentScope, isBatching, isComputed, isEffect, isReactive, isRef, isShallow, isSignal, memoEffect, nextTick, onScopeDispose, queueJob, queuePreFlushCb, reactive, ref, setCurrentScope, shallowReactive, shallowSignal, signal, startBatch, stop, toRaw, toReactive, trigger, untrack, watch };
|