@vue/reactivity 3.4.26 → 3.5.0-alpha.1

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.
@@ -19,186 +19,6 @@ export declare enum ReactiveFlags {
19
19
  RAW = "__v_raw"
20
20
  }
21
21
 
22
- type Dep = Map<ReactiveEffect, number> & {
23
- cleanup: () => void;
24
- computed?: ComputedRefImpl<any>;
25
- };
26
-
27
- export declare class EffectScope {
28
- detached: boolean;
29
- constructor(detached?: boolean);
30
- get active(): boolean;
31
- run<T>(fn: () => T): T | undefined;
32
- stop(fromParent?: boolean): void;
33
- }
34
- /**
35
- * Creates an effect scope object which can capture the reactive effects (i.e.
36
- * computed and watchers) created within it so that these effects can be
37
- * disposed together. For detailed use cases of this API, please consult its
38
- * corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
39
- *
40
- * @param detached - Can be used to create a "detached" effect scope.
41
- * @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
42
- */
43
- export declare function effectScope(detached?: boolean): EffectScope;
44
- /**
45
- * Returns the current active effect scope if there is one.
46
- *
47
- * @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
48
- */
49
- export declare function getCurrentScope(): EffectScope | undefined;
50
- /**
51
- * Registers a dispose callback on the current active effect scope. The
52
- * callback will be invoked when the associated effect scope is stopped.
53
- *
54
- * @param fn - The callback function to attach to the scope's cleanup.
55
- * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
56
- */
57
- export declare function onScopeDispose(fn: () => void): void;
58
-
59
- export type EffectScheduler = (...args: any[]) => any;
60
- export type DebuggerEvent = {
61
- effect: ReactiveEffect;
62
- } & DebuggerEventExtraInfo;
63
- export type DebuggerEventExtraInfo = {
64
- target: object;
65
- type: TrackOpTypes | TriggerOpTypes;
66
- key: any;
67
- newValue?: any;
68
- oldValue?: any;
69
- oldTarget?: Map<any, any> | Set<any>;
70
- };
71
- export declare class ReactiveEffect<T = any> {
72
- fn: () => T;
73
- trigger: () => void;
74
- scheduler?: EffectScheduler | undefined;
75
- active: boolean;
76
- deps: Dep[];
77
- onStop?: () => void;
78
- onTrack?: (event: DebuggerEvent) => void;
79
- onTrigger?: (event: DebuggerEvent) => void;
80
- constructor(fn: () => T, trigger: () => void, scheduler?: EffectScheduler | undefined, scope?: EffectScope);
81
- get dirty(): boolean;
82
- set dirty(v: boolean);
83
- run(): T;
84
- stop(): void;
85
- }
86
- export interface DebuggerOptions {
87
- onTrack?: (event: DebuggerEvent) => void;
88
- onTrigger?: (event: DebuggerEvent) => void;
89
- }
90
- export interface ReactiveEffectOptions extends DebuggerOptions {
91
- lazy?: boolean;
92
- scheduler?: EffectScheduler;
93
- scope?: EffectScope;
94
- allowRecurse?: boolean;
95
- onStop?: () => void;
96
- }
97
- export interface ReactiveEffectRunner<T = any> {
98
- (): T;
99
- effect: ReactiveEffect;
100
- }
101
- /**
102
- * Registers the given function to track reactive updates.
103
- *
104
- * The given function will be run once immediately. Every time any reactive
105
- * property that's accessed within it gets updated, the function will run again.
106
- *
107
- * @param fn - The function that will track reactive updates.
108
- * @param options - Allows to control the effect's behaviour.
109
- * @returns A runner that can be used to control the effect after creation.
110
- */
111
- export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner;
112
- /**
113
- * Stops the effect associated with the given runner.
114
- *
115
- * @param runner - Association with the effect to stop tracking.
116
- */
117
- export declare function stop(runner: ReactiveEffectRunner): void;
118
- /**
119
- * Temporarily pauses tracking.
120
- */
121
- export declare function pauseTracking(): void;
122
- /**
123
- * Re-enables effect tracking (if it was paused).
124
- */
125
- export declare function enableTracking(): void;
126
- /**
127
- * Resets the previous global effect tracking state.
128
- */
129
- export declare function resetTracking(): void;
130
- export declare function pauseScheduling(): void;
131
- export declare function resetScheduling(): void;
132
-
133
- declare const ComputedRefSymbol: unique symbol;
134
- export interface ComputedRef<T = any> extends WritableComputedRef<T> {
135
- readonly value: T;
136
- [ComputedRefSymbol]: true;
137
- }
138
- export interface WritableComputedRef<T> extends Ref<T> {
139
- readonly effect: ReactiveEffect<T>;
140
- }
141
- export type ComputedGetter<T> = (oldValue?: T) => T;
142
- export type ComputedSetter<T> = (newValue: T) => void;
143
- export interface WritableComputedOptions<T> {
144
- get: ComputedGetter<T>;
145
- set: ComputedSetter<T>;
146
- }
147
- export declare class ComputedRefImpl<T> {
148
- private getter;
149
- private readonly _setter;
150
- dep?: Dep;
151
- private _value;
152
- readonly effect: ReactiveEffect<T>;
153
- readonly __v_isRef = true;
154
- readonly [ReactiveFlags.IS_READONLY]: boolean;
155
- _cacheable: boolean;
156
- /**
157
- * Dev only
158
- */
159
- _warnRecursive?: boolean;
160
- constructor(getter: ComputedGetter<T>, _setter: ComputedSetter<T>, isReadonly: boolean, isSSR: boolean);
161
- get value(): T;
162
- set value(newValue: T);
163
- get _dirty(): boolean;
164
- set _dirty(v: boolean);
165
- }
166
- /**
167
- * Takes a getter function and returns a readonly reactive ref object for the
168
- * returned value from the getter. It can also take an object with get and set
169
- * functions to create a writable ref object.
170
- *
171
- * @example
172
- * ```js
173
- * // Creating a readonly computed ref:
174
- * const count = ref(1)
175
- * const plusOne = computed(() => count.value + 1)
176
- *
177
- * console.log(plusOne.value) // 2
178
- * plusOne.value++ // error
179
- * ```
180
- *
181
- * ```js
182
- * // Creating a writable computed ref:
183
- * const count = ref(1)
184
- * const plusOne = computed({
185
- * get: () => count.value + 1,
186
- * set: (val) => {
187
- * count.value = val - 1
188
- * }
189
- * })
190
- *
191
- * plusOne.value = 1
192
- * console.log(count.value) // 0
193
- * ```
194
- *
195
- * @param getter - Function that produces the next value.
196
- * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
197
- * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
198
- */
199
- export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
200
- export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
201
-
202
22
  export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
203
23
  /**
204
24
  * Returns a reactive proxy of the object.
@@ -407,6 +227,177 @@ export type Raw<T> = T & {
407
227
  * @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
408
228
  */
409
229
  export declare function markRaw<T extends object>(value: T): Raw<T>;
230
+ /**
231
+ * Returns a reactive proxy of the given value (if possible).
232
+ *
233
+ * If the given value is not an object, the original value itself is returned.
234
+ *
235
+ * @param value - The value for which a reactive proxy shall be created.
236
+ */
237
+ export declare const toReactive: <T extends unknown>(value: T) => T;
238
+ /**
239
+ * Returns a readonly proxy of the given value (if possible).
240
+ *
241
+ * If the given value is not an object, the original value itself is returned.
242
+ *
243
+ * @param value - The value for which a readonly proxy shall be created.
244
+ */
245
+ export declare const toReadonly: <T extends unknown>(value: T) => DeepReadonly<T>;
246
+
247
+ export type EffectScheduler = (...args: any[]) => any;
248
+ export type DebuggerEvent = {
249
+ effect: Subscriber;
250
+ } & DebuggerEventExtraInfo;
251
+ export type DebuggerEventExtraInfo = {
252
+ target: object;
253
+ type: TrackOpTypes | TriggerOpTypes;
254
+ key: any;
255
+ newValue?: any;
256
+ oldValue?: any;
257
+ oldTarget?: Map<any, any> | Set<any>;
258
+ };
259
+ export interface DebuggerOptions {
260
+ onTrack?: (event: DebuggerEvent) => void;
261
+ onTrigger?: (event: DebuggerEvent) => void;
262
+ }
263
+ export interface ReactiveEffectOptions extends DebuggerOptions {
264
+ scheduler?: EffectScheduler;
265
+ allowRecurse?: boolean;
266
+ onStop?: () => void;
267
+ }
268
+ export declare enum EffectFlags {
269
+ ACTIVE = 1,
270
+ RUNNING = 2,
271
+ TRACKING = 4,
272
+ NOTIFIED = 8,
273
+ DIRTY = 16,
274
+ ALLOW_RECURSE = 32,
275
+ NO_BATCH = 64
276
+ }
277
+ /**
278
+ * Subscriber is a type that tracks (or subscribes to) a list of deps.
279
+ */
280
+ interface Subscriber extends DebuggerOptions {
281
+ }
282
+ export declare class ReactiveEffect<T = any> implements Subscriber, ReactiveEffectOptions {
283
+ fn: () => T;
284
+ scheduler?: EffectScheduler;
285
+ onStop?: () => void;
286
+ onTrack?: (event: DebuggerEvent) => void;
287
+ onTrigger?: (event: DebuggerEvent) => void;
288
+ constructor(fn: () => T);
289
+ run(): T;
290
+ stop(): void;
291
+ trigger(): void;
292
+ get dirty(): boolean;
293
+ }
294
+ export interface ReactiveEffectRunner<T = any> {
295
+ (): T;
296
+ effect: ReactiveEffect;
297
+ }
298
+ export interface ReactiveEffectRunner<T = any> {
299
+ (): T;
300
+ effect: ReactiveEffect;
301
+ }
302
+ export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner<T>;
303
+ /**
304
+ * Stops the effect associated with the given runner.
305
+ *
306
+ * @param runner - Association with the effect to stop tracking.
307
+ */
308
+ export declare function stop(runner: ReactiveEffectRunner): void;
309
+ /**
310
+ * Temporarily pauses tracking.
311
+ */
312
+ export declare function pauseTracking(): void;
313
+ /**
314
+ * Re-enables effect tracking (if it was paused).
315
+ */
316
+ export declare function enableTracking(): void;
317
+ /**
318
+ * Resets the previous global effect tracking state.
319
+ */
320
+ export declare function resetTracking(): void;
321
+ /**
322
+ * Registers a cleanup function for the current active effect.
323
+ * The cleanup function is called right before the next effect run, or when the
324
+ * effect is stopped.
325
+ *
326
+ * Throws a warning iff there is no currenct active effect. The warning can be
327
+ * suppressed by passing `true` to the second argument.
328
+ *
329
+ * @param fn - the cleanup function to be registered
330
+ * @param failSilently - if `true`, will not throw warning when called without
331
+ * an active effect.
332
+ */
333
+ export declare function onEffectCleanup(fn: () => void, failSilently?: boolean): void;
334
+
335
+ declare const ComputedRefSymbol: unique symbol;
336
+ export interface ComputedRef<T = any> extends WritableComputedRef<T> {
337
+ readonly value: T;
338
+ [ComputedRefSymbol]: true;
339
+ }
340
+ export interface WritableComputedRef<T> extends Ref<T> {
341
+ /**
342
+ * @deprecated computed no longer uses effect
343
+ */
344
+ effect: ComputedRefImpl;
345
+ }
346
+ export type ComputedGetter<T> = (oldValue?: T) => T;
347
+ export type ComputedSetter<T> = (newValue: T) => void;
348
+ export interface WritableComputedOptions<T> {
349
+ get: ComputedGetter<T>;
350
+ set: ComputedSetter<T>;
351
+ }
352
+ /**
353
+ * @private exported by @vue/reactivity for Vue core use, but not exported from
354
+ * the main vue package
355
+ */
356
+ export declare class ComputedRefImpl<T = any> implements Subscriber {
357
+ fn: ComputedGetter<T>;
358
+ private readonly setter;
359
+ effect: this;
360
+ onTrack?: (event: DebuggerEvent) => void;
361
+ onTrigger?: (event: DebuggerEvent) => void;
362
+ constructor(fn: ComputedGetter<T>, setter: ComputedSetter<T> | undefined, isSSR: boolean);
363
+ get value(): any;
364
+ set value(newValue: any);
365
+ }
366
+ /**
367
+ * Takes a getter function and returns a readonly reactive ref object for the
368
+ * returned value from the getter. It can also take an object with get and set
369
+ * functions to create a writable ref object.
370
+ *
371
+ * @example
372
+ * ```js
373
+ * // Creating a readonly computed ref:
374
+ * const count = ref(1)
375
+ * const plusOne = computed(() => count.value + 1)
376
+ *
377
+ * console.log(plusOne.value) // 2
378
+ * plusOne.value++ // error
379
+ * ```
380
+ *
381
+ * ```js
382
+ * // Creating a writable computed ref:
383
+ * const count = ref(1)
384
+ * const plusOne = computed({
385
+ * get: () => count.value + 1,
386
+ * set: (val) => {
387
+ * count.value = val - 1
388
+ * }
389
+ * })
390
+ *
391
+ * plusOne.value = 1
392
+ * console.log(count.value) // 0
393
+ * ```
394
+ *
395
+ * @param getter - Function that produces the next value.
396
+ * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
397
+ * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
398
+ */
399
+ export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
400
+ export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
410
401
 
411
402
  declare const RefSymbol: unique symbol;
412
403
  declare const RawSymbol: unique symbol;
@@ -633,12 +624,9 @@ type UnwrapRefSimple<T> = T extends Function | BaseTypes | Ref | RefUnwrapBailTy
633
624
  [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>;
634
625
  } : T;
635
626
 
636
- /**
637
- * @deprecated use `computed` instead. See #5912
638
- */
639
- export declare const deferredComputed: typeof computed;
640
-
641
627
  export declare const ITERATE_KEY: unique symbol;
628
+ export declare const MAP_KEY_ITERATE_KEY: unique symbol;
629
+ export declare const ARRAY_ITERATE_KEY: unique symbol;
642
630
  /**
643
631
  * Tracks access to a reactive property.
644
632
  *
@@ -660,3 +648,46 @@ export declare function track(target: object, type: TrackOpTypes, key: unknown):
660
648
  */
661
649
  export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
662
650
 
651
+ export declare class EffectScope {
652
+ detached: boolean;
653
+ constructor(detached?: boolean);
654
+ get active(): boolean;
655
+ run<T>(fn: () => T): T | undefined;
656
+ stop(fromParent?: boolean): void;
657
+ }
658
+ /**
659
+ * Creates an effect scope object which can capture the reactive effects (i.e.
660
+ * computed and watchers) created within it so that these effects can be
661
+ * disposed together. For detailed use cases of this API, please consult its
662
+ * corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
663
+ *
664
+ * @param detached - Can be used to create a "detached" effect scope.
665
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
666
+ */
667
+ export declare function effectScope(detached?: boolean): EffectScope;
668
+ /**
669
+ * Returns the current active effect scope if there is one.
670
+ *
671
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
672
+ */
673
+ export declare function getCurrentScope(): EffectScope | undefined;
674
+ /**
675
+ * Registers a dispose callback on the current active effect scope. The
676
+ * callback will be invoked when the associated effect scope is stopped.
677
+ *
678
+ * @param fn - The callback function to attach to the scope's cleanup.
679
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
680
+ */
681
+ export declare function onScopeDispose(fn: () => void, failSilently?: boolean): void;
682
+
683
+ /**
684
+ * Track array iteration and return:
685
+ * - if input is reactive: a cloned raw array with reactive values
686
+ * - if input is non-reactive or shallowReactive: the original raw array
687
+ */
688
+ export declare function reactiveReadArray<T>(array: T[]): T[];
689
+ /**
690
+ * Track array iteration and return raw array
691
+ */
692
+ export declare function shallowReadArray<T>(arr: T[]): T[];
693
+