@vue/reactivity 3.3.9 → 3.4.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,6 +11,18 @@ export declare const enum TriggerOpTypes {
11
11
  DELETE = "delete",
12
12
  CLEAR = "clear"
13
13
  }
14
+ export declare const enum ReactiveFlags {
15
+ SKIP = "__v_skip",
16
+ IS_REACTIVE = "__v_isReactive",
17
+ IS_READONLY = "__v_isReadonly",
18
+ IS_SHALLOW = "__v_isShallow",
19
+ RAW = "__v_raw"
20
+ }
21
+
22
+ type Dep = Map<ReactiveEffect, number> & {
23
+ cleanup: () => void;
24
+ computed?: ComputedRefImpl<any>;
25
+ };
14
26
 
15
27
  export declare class EffectScope {
16
28
  detached: boolean;
@@ -44,23 +56,6 @@ export declare function getCurrentScope(): EffectScope | undefined;
44
56
  */
45
57
  export declare function onScopeDispose(fn: () => void): void;
46
58
 
47
- type Dep = Set<ReactiveEffect> & TrackedMarkers;
48
- /**
49
- * wasTracked and newTracked maintain the status for several levels of effect
50
- * tracking recursion. One bit per level is used to define whether the dependency
51
- * was/is tracked.
52
- */
53
- type TrackedMarkers = {
54
- /**
55
- * wasTracked
56
- */
57
- w: number;
58
- /**
59
- * newTracked
60
- */
61
- n: number;
62
- };
63
-
64
59
  export type EffectScheduler = (...args: any[]) => any;
65
60
  export type DebuggerEvent = {
66
61
  effect: ReactiveEffect;
@@ -73,18 +68,19 @@ export type DebuggerEventExtraInfo = {
73
68
  oldValue?: any;
74
69
  oldTarget?: Map<any, any> | Set<any>;
75
70
  };
76
- export declare const ITERATE_KEY: unique symbol;
77
71
  export declare class ReactiveEffect<T = any> {
78
72
  fn: () => T;
79
- scheduler: EffectScheduler | null;
73
+ trigger: () => void;
74
+ scheduler?: EffectScheduler | undefined;
80
75
  active: boolean;
81
76
  deps: Dep[];
82
- parent: ReactiveEffect | undefined;
83
77
  onStop?: () => void;
84
78
  onTrack?: (event: DebuggerEvent) => void;
85
79
  onTrigger?: (event: DebuggerEvent) => void;
86
- constructor(fn: () => T, scheduler?: EffectScheduler | null, scope?: EffectScope);
87
- run(): T | undefined;
80
+ constructor(fn: () => T, trigger: () => void, scheduler?: EffectScheduler | undefined, scope?: EffectScope);
81
+ get dirty(): boolean;
82
+ set dirty(v: boolean);
83
+ run(): T;
88
84
  stop(): void;
89
85
  }
90
86
  export interface DebuggerOptions {
@@ -131,34 +127,73 @@ export declare function enableTracking(): void;
131
127
  * Resets the previous global effect tracking state.
132
128
  */
133
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
+ declare class ComputedRefImpl<T> {
148
+ private readonly _setter;
149
+ dep?: Dep;
150
+ private _value;
151
+ readonly effect: ReactiveEffect<T>;
152
+ readonly __v_isRef = true;
153
+ readonly [ReactiveFlags.IS_READONLY]: boolean;
154
+ _cacheable: boolean;
155
+ constructor(getter: ComputedGetter<T>, _setter: ComputedSetter<T>, isReadonly: boolean, isSSR: boolean);
156
+ get value(): T;
157
+ set value(newValue: T);
158
+ get _dirty(): boolean;
159
+ set _dirty(v: boolean);
160
+ }
134
161
  /**
135
- * Tracks access to a reactive property.
162
+ * Takes a getter function and returns a readonly reactive ref object for the
163
+ * returned value from the getter. It can also take an object with get and set
164
+ * functions to create a writable ref object.
136
165
  *
137
- * This will check which effect is running at the moment and record it as dep
138
- * which records all effects that depend on the reactive property.
166
+ * @example
167
+ * ```js
168
+ * // Creating a readonly computed ref:
169
+ * const count = ref(1)
170
+ * const plusOne = computed(() => count.value + 1)
139
171
  *
140
- * @param target - Object holding the reactive property.
141
- * @param type - Defines the type of access to the reactive property.
142
- * @param key - Identifier of the reactive property to track.
143
- */
144
- export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
145
- /**
146
- * Finds all deps associated with the target (or a specific property) and
147
- * triggers the effects stored within.
172
+ * console.log(plusOne.value) // 2
173
+ * plusOne.value++ // error
174
+ * ```
148
175
  *
149
- * @param target - The reactive object.
150
- * @param type - Defines the type of the operation that needs to trigger effects.
151
- * @param key - Can be used to target a specific reactive property in the target object.
176
+ * ```js
177
+ * // Creating a writable computed ref:
178
+ * const count = ref(1)
179
+ * const plusOne = computed({
180
+ * get: () => count.value + 1,
181
+ * set: (val) => {
182
+ * count.value = val - 1
183
+ * }
184
+ * })
185
+ *
186
+ * plusOne.value = 1
187
+ * console.log(count.value) // 0
188
+ * ```
189
+ *
190
+ * @param getter - Function that produces the next value.
191
+ * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
192
+ * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
152
193
  */
153
- export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
194
+ export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
195
+ export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
154
196
 
155
- export declare const enum ReactiveFlags {
156
- SKIP = "__v_skip",
157
- IS_REACTIVE = "__v_isReactive",
158
- IS_READONLY = "__v_isReadonly",
159
- IS_SHALLOW = "__v_isShallow",
160
- RAW = "__v_raw"
161
- }
162
197
  export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
163
198
  /**
164
199
  * Returns a reactive proxy of the object.
@@ -368,56 +403,6 @@ export type Raw<T> = T & {
368
403
  */
369
404
  export declare function markRaw<T extends object>(value: T): Raw<T>;
370
405
 
371
- declare const ComputedRefSymbol: unique symbol;
372
- export interface ComputedRef<T = any> extends WritableComputedRef<T> {
373
- readonly value: T;
374
- [ComputedRefSymbol]: true;
375
- }
376
- export interface WritableComputedRef<T> extends Ref<T> {
377
- readonly effect: ReactiveEffect<T>;
378
- }
379
- export type ComputedGetter<T> = (...args: any[]) => T;
380
- export type ComputedSetter<T> = (v: T) => void;
381
- export interface WritableComputedOptions<T> {
382
- get: ComputedGetter<T>;
383
- set: ComputedSetter<T>;
384
- }
385
- /**
386
- * Takes a getter function and returns a readonly reactive ref object for the
387
- * returned value from the getter. It can also take an object with get and set
388
- * functions to create a writable ref object.
389
- *
390
- * @example
391
- * ```js
392
- * // Creating a readonly computed ref:
393
- * const count = ref(1)
394
- * const plusOne = computed(() => count.value + 1)
395
- *
396
- * console.log(plusOne.value) // 2
397
- * plusOne.value++ // error
398
- * ```
399
- *
400
- * ```js
401
- * // Creating a writable computed ref:
402
- * const count = ref(1)
403
- * const plusOne = computed({
404
- * get: () => count.value + 1,
405
- * set: (val) => {
406
- * count.value = val - 1
407
- * }
408
- * })
409
- *
410
- * plusOne.value = 1
411
- * console.log(count.value) // 0
412
- * ```
413
- *
414
- * @param getter - Function that produces the next value.
415
- * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
416
- * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
417
- */
418
- export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
419
- export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
420
-
421
406
  type CollectionTypes = IterableCollections | WeakCollections;
422
407
  type IterableCollections = Map<any, any> | Set<any>;
423
408
  type WeakCollections = WeakMap<any, any> | WeakSet<any>;
@@ -649,5 +634,30 @@ type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
649
634
  [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>;
650
635
  } : T;
651
636
 
652
- export declare function deferredComputed<T>(getter: () => T): ComputedRef<T>;
637
+ /**
638
+ * @deprecated use `computed` instead. See #5912
639
+ */
640
+ export declare const deferredComputed: typeof computed;
641
+
642
+ export declare const ITERATE_KEY: unique symbol;
643
+ /**
644
+ * Tracks access to a reactive property.
645
+ *
646
+ * This will check which effect is running at the moment and record it as dep
647
+ * which records all effects that depend on the reactive property.
648
+ *
649
+ * @param target - Object holding the reactive property.
650
+ * @param type - Defines the type of access to the reactive property.
651
+ * @param key - Identifier of the reactive property to track.
652
+ */
653
+ export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
654
+ /**
655
+ * Finds all deps associated with the target (or a specific property) and
656
+ * triggers the effects stored within.
657
+ *
658
+ * @param target - The reactive object.
659
+ * @param type - Defines the type of the operation that needs to trigger effects.
660
+ * @param key - Can be used to target a specific reactive property in the target object.
661
+ */
662
+ export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
653
663