@vue/reactivity 3.5.17 → 3.6.0-alpha.2

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.
@@ -11,7 +11,7 @@ export declare enum TriggerOpTypes {
11
11
  DELETE = "delete",
12
12
  CLEAR = "clear"
13
13
  }
14
- export declare enum ReactiveFlags {
14
+ export declare enum ReactiveFlags$1 {
15
15
  SKIP = "__v_skip",
16
16
  IS_REACTIVE = "__v_isReactive",
17
17
  IS_READONLY = "__v_isReadonly",
@@ -20,6 +20,238 @@ export declare enum ReactiveFlags {
20
20
  IS_REF = "__v_isRef"
21
21
  }
22
22
 
23
+ export declare class EffectScope implements ReactiveNode {
24
+ deps: Link | undefined;
25
+ depsTail: Link | undefined;
26
+ subs: Link | undefined;
27
+ subsTail: Link | undefined;
28
+ flags: number;
29
+ constructor(detached?: boolean);
30
+ get active(): boolean;
31
+ pause(): void;
32
+ /**
33
+ * Resumes the effect scope, including all child scopes and effects.
34
+ */
35
+ resume(): void;
36
+ run<T>(fn: () => T): T | undefined;
37
+ stop(): void;
38
+ }
39
+ /**
40
+ * Creates an effect scope object which can capture the reactive effects (i.e.
41
+ * computed and watchers) created within it so that these effects can be
42
+ * disposed together. For detailed use cases of this API, please consult its
43
+ * corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
44
+ *
45
+ * @param detached - Can be used to create a "detached" effect scope.
46
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
47
+ */
48
+ export declare function effectScope(detached?: boolean): EffectScope;
49
+ /**
50
+ * Returns the current active effect scope if there is one.
51
+ *
52
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
53
+ */
54
+ export declare function getCurrentScope(): EffectScope | undefined;
55
+ export declare function setCurrentScope(scope?: EffectScope): EffectScope | undefined;
56
+ /**
57
+ * Registers a dispose callback on the current active effect scope. The
58
+ * callback will be invoked when the associated effect scope is stopped.
59
+ *
60
+ * @param fn - The callback function to attach to the scope's cleanup.
61
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
62
+ */
63
+ export declare function onScopeDispose(fn: () => void, failSilently?: boolean): void;
64
+
65
+ interface ReactiveNode {
66
+ deps?: Link;
67
+ depsTail?: Link;
68
+ subs?: Link;
69
+ subsTail?: Link;
70
+ flags: ReactiveFlags;
71
+ }
72
+ interface Link {
73
+ dep: ReactiveNode | ComputedRefImpl | ReactiveEffect | EffectScope;
74
+ sub: ReactiveNode | ComputedRefImpl | ReactiveEffect | EffectScope;
75
+ prevSub: Link | undefined;
76
+ nextSub: Link | undefined;
77
+ prevDep: Link | undefined;
78
+ nextDep: Link | undefined;
79
+ }
80
+ declare const enum ReactiveFlags {
81
+ None = 0,
82
+ Mutable = 1,
83
+ Watching = 2,
84
+ RecursedCheck = 4,
85
+ Recursed = 8,
86
+ Dirty = 16,
87
+ Pending = 32
88
+ }
89
+
90
+ export type EffectScheduler = (...args: any[]) => any;
91
+ export type DebuggerEvent = {
92
+ effect: ReactiveNode;
93
+ } & DebuggerEventExtraInfo;
94
+ export type DebuggerEventExtraInfo = {
95
+ target: object;
96
+ type: TrackOpTypes | TriggerOpTypes;
97
+ key: any;
98
+ newValue?: any;
99
+ oldValue?: any;
100
+ oldTarget?: Map<any, any> | Set<any>;
101
+ };
102
+ export interface DebuggerOptions {
103
+ onTrack?: (event: DebuggerEvent) => void;
104
+ onTrigger?: (event: DebuggerEvent) => void;
105
+ }
106
+ export interface ReactiveEffectOptions extends DebuggerOptions {
107
+ scheduler?: EffectScheduler;
108
+ onStop?: () => void;
109
+ }
110
+ export declare enum EffectFlags {
111
+ /**
112
+ * ReactiveEffect only
113
+ */
114
+ ALLOW_RECURSE = 128,
115
+ PAUSED = 256,
116
+ STOP = 1024
117
+ }
118
+ export declare class ReactiveEffect<T = any> implements ReactiveEffectOptions, ReactiveNode {
119
+ deps: Link | undefined;
120
+ depsTail: Link | undefined;
121
+ subs: Link | undefined;
122
+ subsTail: Link | undefined;
123
+ flags: number;
124
+ onTrack?: (event: DebuggerEvent) => void;
125
+ onTrigger?: (event: DebuggerEvent) => void;
126
+ fn(): T;
127
+ constructor(fn?: () => T);
128
+ get active(): boolean;
129
+ pause(): void;
130
+ resume(): void;
131
+ notify(): void;
132
+ run(): T;
133
+ stop(): void;
134
+ get dirty(): boolean;
135
+ }
136
+ export interface ReactiveEffectRunner<T = any> {
137
+ (): T;
138
+ effect: ReactiveEffect;
139
+ }
140
+ export interface ReactiveEffectRunner<T = any> {
141
+ (): T;
142
+ effect: ReactiveEffect;
143
+ }
144
+ export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner<T>;
145
+ /**
146
+ * Stops the effect associated with the given runner.
147
+ *
148
+ * @param runner - Association with the effect to stop tracking.
149
+ */
150
+ export declare function stop(runner: ReactiveEffectRunner): void;
151
+ /**
152
+ * Temporarily pauses tracking.
153
+ */
154
+ export declare function pauseTracking(): void;
155
+ /**
156
+ * Re-enables effect tracking (if it was paused).
157
+ */
158
+ export declare function enableTracking(): void;
159
+ /**
160
+ * Resets the previous global effect tracking state.
161
+ */
162
+ export declare function resetTracking(): void;
163
+ /**
164
+ * Registers a cleanup function for the current active effect.
165
+ * The cleanup function is called right before the next effect run, or when the
166
+ * effect is stopped.
167
+ *
168
+ * Throws a warning if there is no current active effect. The warning can be
169
+ * suppressed by passing `true` to the second argument.
170
+ *
171
+ * @param fn - the cleanup function to be registered
172
+ * @param failSilently - if `true`, will not throw warning when called without
173
+ * an active effect.
174
+ */
175
+ export declare function onEffectCleanup(fn: () => void, failSilently?: boolean): void;
176
+
177
+ declare const ComputedRefSymbol: unique symbol;
178
+ declare const WritableComputedRefSymbol: unique symbol;
179
+ interface BaseComputedRef<T, S = T> extends Ref<T, S> {
180
+ [ComputedRefSymbol]: true;
181
+ /**
182
+ * @deprecated computed no longer uses effect
183
+ */
184
+ effect: ComputedRefImpl;
185
+ }
186
+ export interface ComputedRef<T = any> extends BaseComputedRef<T> {
187
+ readonly value: T;
188
+ }
189
+ export interface WritableComputedRef<T, S = T> extends BaseComputedRef<T, S> {
190
+ [WritableComputedRefSymbol]: true;
191
+ }
192
+ export type ComputedGetter<T> = (oldValue?: T) => T;
193
+ export type ComputedSetter<T> = (newValue: T) => void;
194
+ export interface WritableComputedOptions<T, S = T> {
195
+ get: ComputedGetter<T>;
196
+ set: ComputedSetter<S>;
197
+ }
198
+ /**
199
+ * @private exported by @vue/reactivity for Vue core use, but not exported from
200
+ * the main vue package
201
+ */
202
+ export declare class ComputedRefImpl<T = any> implements ReactiveNode {
203
+ fn: ComputedGetter<T>;
204
+ private readonly setter;
205
+ subs: Link | undefined;
206
+ subsTail: Link | undefined;
207
+ deps: Link | undefined;
208
+ depsTail: Link | undefined;
209
+ flags: ReactiveFlags;
210
+ get effect(): this;
211
+ get dep(): ReactiveNode;
212
+ onTrack?: (event: DebuggerEvent) => void;
213
+ onTrigger?: (event: DebuggerEvent) => void;
214
+ constructor(fn: ComputedGetter<T>, setter: ComputedSetter<T> | undefined);
215
+ get value(): T;
216
+ set value(newValue: T);
217
+ update(): boolean;
218
+ }
219
+ /**
220
+ * Takes a getter function and returns a readonly reactive ref object for the
221
+ * returned value from the getter. It can also take an object with get and set
222
+ * functions to create a writable ref object.
223
+ *
224
+ * @example
225
+ * ```js
226
+ * // Creating a readonly computed ref:
227
+ * const count = ref(1)
228
+ * const plusOne = computed(() => count.value + 1)
229
+ *
230
+ * console.log(plusOne.value) // 2
231
+ * plusOne.value++ // error
232
+ * ```
233
+ *
234
+ * ```js
235
+ * // Creating a writable computed ref:
236
+ * const count = ref(1)
237
+ * const plusOne = computed({
238
+ * get: () => count.value + 1,
239
+ * set: (val) => {
240
+ * count.value = val - 1
241
+ * }
242
+ * })
243
+ *
244
+ * plusOne.value = 1
245
+ * console.log(count.value) // 0
246
+ * ```
247
+ *
248
+ * @param getter - Function that produces the next value.
249
+ * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
250
+ * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
251
+ */
252
+ export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
253
+ export declare function computed<T, S = T>(options: WritableComputedOptions<T, S>, debugOptions?: DebuggerOptions): WritableComputedRef<T, S>;
254
+
23
255
  export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
24
256
  declare const ReactiveMarkerSymbol: unique symbol;
25
257
  export interface ReactiveMarker {
@@ -250,171 +482,6 @@ export declare const toReactive: <T extends unknown>(value: T) => T;
250
482
  */
251
483
  export declare const toReadonly: <T extends unknown>(value: T) => DeepReadonly<T>;
252
484
 
253
- export type EffectScheduler = (...args: any[]) => any;
254
- export type DebuggerEvent = {
255
- effect: Subscriber;
256
- } & DebuggerEventExtraInfo;
257
- export type DebuggerEventExtraInfo = {
258
- target: object;
259
- type: TrackOpTypes | TriggerOpTypes;
260
- key: any;
261
- newValue?: any;
262
- oldValue?: any;
263
- oldTarget?: Map<any, any> | Set<any>;
264
- };
265
- export interface DebuggerOptions {
266
- onTrack?: (event: DebuggerEvent) => void;
267
- onTrigger?: (event: DebuggerEvent) => void;
268
- }
269
- export interface ReactiveEffectOptions extends DebuggerOptions {
270
- scheduler?: EffectScheduler;
271
- allowRecurse?: boolean;
272
- onStop?: () => void;
273
- }
274
- export declare enum EffectFlags {
275
- /**
276
- * ReactiveEffect only
277
- */
278
- ACTIVE = 1,
279
- RUNNING = 2,
280
- TRACKING = 4,
281
- NOTIFIED = 8,
282
- DIRTY = 16,
283
- ALLOW_RECURSE = 32,
284
- PAUSED = 64,
285
- EVALUATED = 128
286
- }
287
- /**
288
- * Subscriber is a type that tracks (or subscribes to) a list of deps.
289
- */
290
- interface Subscriber extends DebuggerOptions {
291
- }
292
- export declare class ReactiveEffect<T = any> implements Subscriber, ReactiveEffectOptions {
293
- fn: () => T;
294
- scheduler?: EffectScheduler;
295
- onStop?: () => void;
296
- onTrack?: (event: DebuggerEvent) => void;
297
- onTrigger?: (event: DebuggerEvent) => void;
298
- constructor(fn: () => T);
299
- pause(): void;
300
- resume(): void;
301
- run(): T;
302
- stop(): void;
303
- trigger(): void;
304
- get dirty(): boolean;
305
- }
306
- export interface ReactiveEffectRunner<T = any> {
307
- (): T;
308
- effect: ReactiveEffect;
309
- }
310
- export interface ReactiveEffectRunner<T = any> {
311
- (): T;
312
- effect: ReactiveEffect;
313
- }
314
- export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner<T>;
315
- /**
316
- * Stops the effect associated with the given runner.
317
- *
318
- * @param runner - Association with the effect to stop tracking.
319
- */
320
- export declare function stop(runner: ReactiveEffectRunner): void;
321
- /**
322
- * Temporarily pauses tracking.
323
- */
324
- export declare function pauseTracking(): void;
325
- /**
326
- * Re-enables effect tracking (if it was paused).
327
- */
328
- export declare function enableTracking(): void;
329
- /**
330
- * Resets the previous global effect tracking state.
331
- */
332
- export declare function resetTracking(): void;
333
- /**
334
- * Registers a cleanup function for the current active effect.
335
- * The cleanup function is called right before the next effect run, or when the
336
- * effect is stopped.
337
- *
338
- * Throws a warning if there is no current active effect. The warning can be
339
- * suppressed by passing `true` to the second argument.
340
- *
341
- * @param fn - the cleanup function to be registered
342
- * @param failSilently - if `true`, will not throw warning when called without
343
- * an active effect.
344
- */
345
- export declare function onEffectCleanup(fn: () => void, failSilently?: boolean): void;
346
-
347
- declare const ComputedRefSymbol: unique symbol;
348
- declare const WritableComputedRefSymbol: unique symbol;
349
- interface BaseComputedRef<T, S = T> extends Ref<T, S> {
350
- [ComputedRefSymbol]: true;
351
- /**
352
- * @deprecated computed no longer uses effect
353
- */
354
- effect: ComputedRefImpl;
355
- }
356
- export interface ComputedRef<T = any> extends BaseComputedRef<T> {
357
- readonly value: T;
358
- }
359
- export interface WritableComputedRef<T, S = T> extends BaseComputedRef<T, S> {
360
- [WritableComputedRefSymbol]: true;
361
- }
362
- export type ComputedGetter<T> = (oldValue?: T) => T;
363
- export type ComputedSetter<T> = (newValue: T) => void;
364
- export interface WritableComputedOptions<T, S = T> {
365
- get: ComputedGetter<T>;
366
- set: ComputedSetter<S>;
367
- }
368
- /**
369
- * @private exported by @vue/reactivity for Vue core use, but not exported from
370
- * the main vue package
371
- */
372
- export declare class ComputedRefImpl<T = any> implements Subscriber {
373
- fn: ComputedGetter<T>;
374
- private readonly setter;
375
- effect: this;
376
- onTrack?: (event: DebuggerEvent) => void;
377
- onTrigger?: (event: DebuggerEvent) => void;
378
- constructor(fn: ComputedGetter<T>, setter: ComputedSetter<T> | undefined, isSSR: boolean);
379
- get value(): T;
380
- set value(newValue: T);
381
- }
382
- /**
383
- * Takes a getter function and returns a readonly reactive ref object for the
384
- * returned value from the getter. It can also take an object with get and set
385
- * functions to create a writable ref object.
386
- *
387
- * @example
388
- * ```js
389
- * // Creating a readonly computed ref:
390
- * const count = ref(1)
391
- * const plusOne = computed(() => count.value + 1)
392
- *
393
- * console.log(plusOne.value) // 2
394
- * plusOne.value++ // error
395
- * ```
396
- *
397
- * ```js
398
- * // Creating a writable computed ref:
399
- * const count = ref(1)
400
- * const plusOne = computed({
401
- * get: () => count.value + 1,
402
- * set: (val) => {
403
- * count.value = val - 1
404
- * }
405
- * })
406
- *
407
- * plusOne.value = 1
408
- * console.log(count.value) // 0
409
- * ```
410
- *
411
- * @param getter - Function that produces the next value.
412
- * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
413
- * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
414
- */
415
- export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
416
- export declare function computed<T, S = T>(options: WritableComputedOptions<T, S>, debugOptions?: DebuggerOptions): WritableComputedRef<T, S>;
417
-
418
485
  declare const RefSymbol: unique symbol;
419
486
  declare const RawSymbol: unique symbol;
420
487
  export interface Ref<T = any, S = T> {
@@ -662,45 +729,6 @@ export declare function track(target: object, type: TrackOpTypes, key: unknown):
662
729
  */
663
730
  export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
664
731
 
665
- export declare class EffectScope {
666
- detached: boolean;
667
- private _isPaused;
668
- constructor(detached?: boolean);
669
- get active(): boolean;
670
- pause(): void;
671
- /**
672
- * Resumes the effect scope, including all child scopes and effects.
673
- */
674
- resume(): void;
675
- run<T>(fn: () => T): T | undefined;
676
- prevScope: EffectScope | undefined;
677
- stop(fromParent?: boolean): void;
678
- }
679
- /**
680
- * Creates an effect scope object which can capture the reactive effects (i.e.
681
- * computed and watchers) created within it so that these effects can be
682
- * disposed together. For detailed use cases of this API, please consult its
683
- * corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
684
- *
685
- * @param detached - Can be used to create a "detached" effect scope.
686
- * @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
687
- */
688
- export declare function effectScope(detached?: boolean): EffectScope;
689
- /**
690
- * Returns the current active effect scope if there is one.
691
- *
692
- * @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
693
- */
694
- export declare function getCurrentScope(): EffectScope | undefined;
695
- /**
696
- * Registers a dispose callback on the current active effect scope. The
697
- * callback will be invoked when the associated effect scope is stopped.
698
- *
699
- * @param fn - The callback function to attach to the scope's cleanup.
700
- * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
701
- */
702
- export declare function onScopeDispose(fn: () => void, failSilently?: boolean): void;
703
-
704
732
  /**
705
733
  * Track array iteration and return:
706
734
  * - if input is reactive: a cloned raw array with reactive values
@@ -725,7 +753,6 @@ export interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
725
753
  immediate?: Immediate;
726
754
  deep?: boolean | number;
727
755
  once?: boolean;
728
- scheduler?: WatchScheduler;
729
756
  onWarn?: (msg: string, ...args: any[]) => void;
730
757
  }
731
758
  export type WatchStopHandle = () => void;
@@ -734,7 +761,6 @@ export interface WatchHandle extends WatchStopHandle {
734
761
  resume: () => void;
735
762
  stop: () => void;
736
763
  }
737
- export type WatchScheduler = (job: () => void, isFirstRun: boolean) => void;
738
764
  /**
739
765
  * Returns the current active effect if there is one.
740
766
  */
@@ -750,8 +776,18 @@ export declare function getCurrentWatcher(): ReactiveEffect<any> | undefined;
750
776
  * @param owner - The effect that this cleanup function should be attached to.
751
777
  * By default, the current active effect.
752
778
  */
753
- export declare function onWatcherCleanup(cleanupFn: () => void, failSilently?: boolean, owner?: ReactiveEffect | undefined): void;
779
+ export declare function onWatcherCleanup(cleanupFn: () => void, failSilently?: boolean, owner?: WatcherEffect | undefined): void;
780
+ export declare class WatcherEffect extends ReactiveEffect {
781
+ cb?: WatchCallback<any, any> | null | undefined;
782
+ options: WatchOptions;
783
+ forceTrigger: boolean;
784
+ isMultiSource: boolean;
785
+ oldValue: any;
786
+ boundCleanup: typeof onWatcherCleanup;
787
+ constructor(source: WatchSource | WatchSource[] | WatchEffect | object, cb?: WatchCallback<any, any> | null | undefined, options?: WatchOptions);
788
+ run(initialRun?: boolean): void;
789
+ }
754
790
  export declare function watch(source: WatchSource | WatchSource[] | WatchEffect | object, cb?: WatchCallback | null, options?: WatchOptions): WatchHandle;
755
791
  export declare function traverse(value: unknown, depth?: number, seen?: Set<unknown>): unknown;
756
792
 
757
-
793
+ export { ReactiveFlags$1 as ReactiveFlags, };