@vue/reactivity 3.3.6 → 3.4.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.
@@ -1,5 +1,16 @@
1
1
  import { IfAny } from '@vue/shared';
2
2
 
3
+ export declare const enum TrackOpTypes {
4
+ GET = "get",
5
+ HAS = "has",
6
+ ITERATE = "iterate"
7
+ }
8
+ export declare const enum TriggerOpTypes {
9
+ SET = "set",
10
+ ADD = "add",
11
+ DELETE = "delete",
12
+ CLEAR = "clear"
13
+ }
3
14
  export declare const enum ReactiveFlags {
4
15
  SKIP = "__v_skip",
5
16
  IS_REACTIVE = "__v_isReactive",
@@ -7,6 +18,7 @@ export declare const enum ReactiveFlags {
7
18
  IS_SHALLOW = "__v_isShallow",
8
19
  RAW = "__v_raw"
9
20
  }
21
+
10
22
  export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
11
23
  /**
12
24
  * Returns a reactive proxy of the object.
@@ -220,18 +232,6 @@ type CollectionTypes = IterableCollections | WeakCollections;
220
232
  type IterableCollections = Map<any, any> | Set<any>;
221
233
  type WeakCollections = WeakMap<any, any> | WeakSet<any>;
222
234
 
223
- export declare const enum TrackOpTypes {
224
- GET = "get",
225
- HAS = "has",
226
- ITERATE = "iterate"
227
- }
228
- export declare const enum TriggerOpTypes {
229
- SET = "set",
230
- ADD = "add",
231
- DELETE = "delete",
232
- CLEAR = "clear"
233
- }
234
-
235
235
  export declare class EffectScope {
236
236
  detached: boolean;
237
237
  constructor(detached?: boolean);
@@ -276,18 +276,19 @@ export type DebuggerEventExtraInfo = {
276
276
  oldValue?: any;
277
277
  oldTarget?: Map<any, any> | Set<any>;
278
278
  };
279
- export declare const ITERATE_KEY: unique symbol;
280
279
  export declare class ReactiveEffect<T = any> {
281
280
  fn: () => T;
282
- scheduler: EffectScheduler | null;
281
+ trigger: () => void;
282
+ scheduler?: EffectScheduler | undefined;
283
283
  active: boolean;
284
284
  deps: Dep[];
285
- parent: ReactiveEffect | undefined;
286
285
  onStop?: () => void;
287
286
  onTrack?: (event: DebuggerEvent) => void;
288
287
  onTrigger?: (event: DebuggerEvent) => void;
289
- constructor(fn: () => T, scheduler?: EffectScheduler | null, scope?: EffectScope);
290
- run(): T | undefined;
288
+ constructor(fn: () => T, trigger: () => void, scheduler?: EffectScheduler | undefined, scope?: EffectScope);
289
+ get dirty(): boolean;
290
+ set dirty(v: boolean);
291
+ run(): T;
291
292
  stop(): void;
292
293
  }
293
294
  export interface DebuggerOptions {
@@ -334,42 +335,76 @@ export declare function enableTracking(): void;
334
335
  * Resets the previous global effect tracking state.
335
336
  */
336
337
  export declare function resetTracking(): void;
338
+ export declare function pauseScheduling(): void;
339
+ export declare function resetScheduling(): void;
340
+
341
+ declare const ComputedRefSymbol: unique symbol;
342
+ export interface ComputedRef<T = any> extends WritableComputedRef<T> {
343
+ readonly value: T;
344
+ [ComputedRefSymbol]: true;
345
+ }
346
+ export interface WritableComputedRef<T> extends Ref<T> {
347
+ readonly effect: ReactiveEffect<T>;
348
+ }
349
+ export type ComputedGetter<T> = (...args: any[]) => T;
350
+ export type ComputedSetter<T> = (v: T) => void;
351
+ export interface WritableComputedOptions<T> {
352
+ get: ComputedGetter<T>;
353
+ set: ComputedSetter<T>;
354
+ }
355
+ declare class ComputedRefImpl<T> {
356
+ private readonly _setter;
357
+ dep?: Dep;
358
+ private _value;
359
+ readonly effect: ReactiveEffect<T>;
360
+ readonly __v_isRef = true;
361
+ readonly [ReactiveFlags.IS_READONLY]: boolean;
362
+ _cacheable: boolean;
363
+ constructor(getter: ComputedGetter<T>, _setter: ComputedSetter<T>, isReadonly: boolean, isSSR: boolean);
364
+ get value(): T;
365
+ set value(newValue: T);
366
+ get _dirty(): boolean;
367
+ set _dirty(v: boolean);
368
+ }
337
369
  /**
338
- * Tracks access to a reactive property.
370
+ * Takes a getter function and returns a readonly reactive ref object for the
371
+ * returned value from the getter. It can also take an object with get and set
372
+ * functions to create a writable ref object.
339
373
  *
340
- * This will check which effect is running at the moment and record it as dep
341
- * which records all effects that depend on the reactive property.
374
+ * @example
375
+ * ```js
376
+ * // Creating a readonly computed ref:
377
+ * const count = ref(1)
378
+ * const plusOne = computed(() => count.value + 1)
342
379
  *
343
- * @param target - Object holding the reactive property.
344
- * @param type - Defines the type of access to the reactive property.
345
- * @param key - Identifier of the reactive property to track.
346
- */
347
- export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
348
- /**
349
- * Finds all deps associated with the target (or a specific property) and
350
- * triggers the effects stored within.
380
+ * console.log(plusOne.value) // 2
381
+ * plusOne.value++ // error
382
+ * ```
351
383
  *
352
- * @param target - The reactive object.
353
- * @param type - Defines the type of the operation that needs to trigger effects.
354
- * @param key - Can be used to target a specific reactive property in the target object.
384
+ * ```js
385
+ * // Creating a writable computed ref:
386
+ * const count = ref(1)
387
+ * const plusOne = computed({
388
+ * get: () => count.value + 1,
389
+ * set: (val) => {
390
+ * count.value = val - 1
391
+ * }
392
+ * })
393
+ *
394
+ * plusOne.value = 1
395
+ * console.log(count.value) // 0
396
+ * ```
397
+ *
398
+ * @param getter - Function that produces the next value.
399
+ * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
400
+ * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
355
401
  */
356
- export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
402
+ export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
403
+ export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
357
404
 
358
- type Dep = Set<ReactiveEffect> & TrackedMarkers;
359
- /**
360
- * wasTracked and newTracked maintain the status for several levels of effect
361
- * tracking recursion. One bit per level is used to define whether the dependency
362
- * was/is tracked.
363
- */
364
- type TrackedMarkers = {
365
- /**
366
- * wasTracked
367
- */
368
- w: number;
369
- /**
370
- * newTracked
371
- */
372
- n: number;
405
+ type Dep = Map<ReactiveEffect, number> & {
406
+ cleanup: () => void;
407
+ computed?: ComputedRefImpl<any>;
373
408
  };
374
409
 
375
410
  declare const RefSymbol: unique symbol;
@@ -598,55 +633,30 @@ type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
598
633
  [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>;
599
634
  } : T;
600
635
 
601
- declare const ComputedRefSymbol: unique symbol;
602
- export interface ComputedRef<T = any> extends WritableComputedRef<T> {
603
- readonly value: T;
604
- [ComputedRefSymbol]: true;
605
- }
606
- export interface WritableComputedRef<T> extends Ref<T> {
607
- readonly effect: ReactiveEffect<T>;
608
- }
609
- export type ComputedGetter<T> = (...args: any[]) => T;
610
- export type ComputedSetter<T> = (v: T) => void;
611
- export interface WritableComputedOptions<T> {
612
- get: ComputedGetter<T>;
613
- set: ComputedSetter<T>;
614
- }
615
636
  /**
616
- * Takes a getter function and returns a readonly reactive ref object for the
617
- * returned value from the getter. It can also take an object with get and set
618
- * functions to create a writable ref object.
619
- *
620
- * @example
621
- * ```js
622
- * // Creating a readonly computed ref:
623
- * const count = ref(1)
624
- * const plusOne = computed(() => count.value + 1)
625
- *
626
- * console.log(plusOne.value) // 2
627
- * plusOne.value++ // error
628
- * ```
637
+ * @deprecated use `computed` instead. See #5912
638
+ */
639
+ export declare const deferredComputed: typeof computed;
640
+
641
+ export declare const ITERATE_KEY: unique symbol;
642
+ /**
643
+ * Tracks access to a reactive property.
629
644
  *
630
- * ```js
631
- * // Creating a writable computed ref:
632
- * const count = ref(1)
633
- * const plusOne = computed({
634
- * get: () => count.value + 1,
635
- * set: (val) => {
636
- * count.value = val - 1
637
- * }
638
- * })
645
+ * This will check which effect is running at the moment and record it as dep
646
+ * which records all effects that depend on the reactive property.
639
647
  *
640
- * plusOne.value = 1
641
- * console.log(count.value) // 0
642
- * ```
648
+ * @param target - Object holding the reactive property.
649
+ * @param type - Defines the type of access to the reactive property.
650
+ * @param key - Identifier of the reactive property to track.
651
+ */
652
+ export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
653
+ /**
654
+ * Finds all deps associated with the target (or a specific property) and
655
+ * triggers the effects stored within.
643
656
  *
644
- * @param getter - Function that produces the next value.
645
- * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
646
- * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
657
+ * @param target - The reactive object.
658
+ * @param type - Defines the type of the operation that needs to trigger effects.
659
+ * @param key - Can be used to target a specific reactive property in the target object.
647
660
  */
648
- export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
649
- export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
650
-
651
- export declare function deferredComputed<T>(getter: () => T): ComputedRef<T>;
661
+ export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
652
662