@vue/reactivity 3.2.47 → 3.3.0-alpha.10

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,351 +1,676 @@
1
- import { IfAny } from '@vue/shared';
2
-
3
- declare type BaseTypes = string | number | boolean;
4
-
5
- declare type Builtin = Primitive | Function | Date | Error | RegExp;
6
-
7
- declare type CollectionTypes = IterableCollections | WeakCollections;
8
-
9
- export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
10
-
11
- export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
12
-
13
- export declare type ComputedGetter<T> = (...args: any[]) => T;
14
-
15
- export declare interface ComputedRef<T = any> extends WritableComputedRef<T> {
16
- readonly value: T;
17
- [ComputedRefSymbol]: true;
18
- }
19
-
20
- declare class ComputedRefImpl<T> {
21
- private readonly _setter;
22
- dep?: Dep;
23
- private _value;
24
- readonly effect: ReactiveEffect<T>;
25
- readonly __v_isRef = true;
26
- readonly [ReactiveFlags.IS_READONLY]: boolean;
27
- _dirty: boolean;
28
- _cacheable: boolean;
29
- constructor(getter: ComputedGetter<T>, _setter: ComputedSetter<T>, isReadonly: boolean, isSSR: boolean);
30
- get value(): T;
31
- set value(newValue: T);
32
- }
33
-
34
- declare const ComputedRefSymbol: unique symbol;
35
-
36
- export declare type ComputedSetter<T> = (v: T) => void;
37
-
38
- export declare function customRef<T>(factory: CustomRefFactory<T>): Ref<T>;
39
-
40
- export declare type CustomRefFactory<T> = (track: () => void, trigger: () => void) => {
41
- get: () => T;
42
- set: (value: T) => void;
43
- };
44
-
45
- export declare type DebuggerEvent = {
46
- effect: ReactiveEffect;
47
- } & DebuggerEventExtraInfo;
48
-
49
- export declare type DebuggerEventExtraInfo = {
50
- target: object;
51
- type: TrackOpTypes | TriggerOpTypes;
52
- key: any;
53
- newValue?: any;
54
- oldValue?: any;
55
- oldTarget?: Map<any, any> | Set<any>;
56
- };
57
-
58
- export declare interface DebuggerOptions {
59
- onTrack?: (event: DebuggerEvent) => void;
60
- onTrigger?: (event: DebuggerEvent) => void;
61
- }
62
-
63
- export declare type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends Ref<infer U> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? {
64
- readonly [K in keyof T]: DeepReadonly<T[K]>;
65
- } : Readonly<T>;
66
-
67
- export declare function deferredComputed<T>(getter: () => T): ComputedRef<T>;
68
-
69
- declare type Dep = Set<ReactiveEffect> & TrackedMarkers;
70
-
71
- export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner;
72
-
73
- export declare type EffectScheduler = (...args: any[]) => any;
74
-
75
- export declare class EffectScope {
76
- detached: boolean;
77
- /* Excluded from this release type: _active */
78
- /* Excluded from this release type: effects */
79
- /* Excluded from this release type: cleanups */
80
- /* Excluded from this release type: parent */
81
- /* Excluded from this release type: scopes */
82
- /* Excluded from this release type: index */
83
- constructor(detached?: boolean);
84
- get active(): boolean;
85
- run<T>(fn: () => T): T | undefined;
86
- /* Excluded from this release type: on */
87
- /* Excluded from this release type: off */
88
- stop(fromParent?: boolean): void;
89
- }
90
-
91
- export declare function effectScope(detached?: boolean): EffectScope;
92
-
93
- export declare function enableTracking(): void;
94
-
95
- export declare function getCurrentScope(): EffectScope | undefined;
96
-
97
- export declare function isProxy(value: unknown): boolean;
98
-
99
- export declare function isReactive(value: unknown): boolean;
100
-
101
- export declare function isReadonly(value: unknown): boolean;
102
-
103
- export declare function isRef<T>(r: Ref<T> | unknown): r is Ref<T>;
104
-
105
- export declare function isShallow(value: unknown): boolean;
106
-
107
- declare type IterableCollections = Map<any, any> | Set<any>;
108
-
109
- export declare const ITERATE_KEY: unique symbol;
110
-
111
- export declare function markRaw<T extends object>(value: T): Raw<T>;
112
-
113
- export declare function onScopeDispose(fn: () => void): void;
114
-
115
- export declare function pauseTracking(): void;
116
-
117
- declare type Primitive = string | number | boolean | bigint | symbol | undefined | null;
118
-
119
- export declare function proxyRefs<T extends object>(objectWithRefs: T): ShallowUnwrapRef<T>;
120
-
121
- export declare type Raw<T> = T & {
122
- [RawSymbol]?: true;
123
- };
124
-
125
- declare const RawSymbol: unique symbol;
126
-
127
- /**
128
- * Creates a reactive copy of the original object.
129
- *
130
- * The reactive conversion is "deep"—it affects all nested properties. In the
131
- * ES2015 Proxy based implementation, the returned proxy is **not** equal to the
132
- * original object. It is recommended to work exclusively with the reactive
133
- * proxy and avoid relying on the original object.
134
- *
135
- * A reactive object also automatically unwraps refs contained in it, so you
136
- * don't need to use `.value` when accessing and mutating their value:
137
- *
138
- * ```js
139
- * const count = ref(0)
140
- * const obj = reactive({
141
- * count
142
- * })
143
- *
144
- * obj.count++
145
- * obj.count // -> 1
146
- * count.value // -> 1
147
- * ```
148
- */
149
- export declare function reactive<T extends object>(target: T): UnwrapNestedRefs<T>;
150
-
151
- export declare class ReactiveEffect<T = any> {
152
- fn: () => T;
153
- scheduler: EffectScheduler | null;
154
- active: boolean;
155
- deps: Dep[];
156
- parent: ReactiveEffect | undefined;
157
- /* Excluded from this release type: computed */
158
- /* Excluded from this release type: allowRecurse */
159
- /* Excluded from this release type: deferStop */
160
- onStop?: () => void;
161
- onTrack?: (event: DebuggerEvent) => void;
162
- onTrigger?: (event: DebuggerEvent) => void;
163
- constructor(fn: () => T, scheduler?: EffectScheduler | null, scope?: EffectScope);
164
- run(): T | undefined;
165
- stop(): void;
166
- }
167
-
168
- export declare interface ReactiveEffectOptions extends DebuggerOptions {
169
- lazy?: boolean;
170
- scheduler?: EffectScheduler;
171
- scope?: EffectScope;
172
- allowRecurse?: boolean;
173
- onStop?: () => void;
174
- }
175
-
176
- export declare interface ReactiveEffectRunner<T = any> {
177
- (): T;
178
- effect: ReactiveEffect;
179
- }
180
-
181
- export declare const enum ReactiveFlags {
182
- SKIP = "__v_skip",
183
- IS_REACTIVE = "__v_isReactive",
184
- IS_READONLY = "__v_isReadonly",
185
- IS_SHALLOW = "__v_isShallow",
186
- RAW = "__v_raw"
187
- }
188
-
189
- /**
190
- * Creates a readonly copy of the original object. Note the returned copy is not
191
- * made reactive, but `readonly` can be called on an already reactive object.
192
- */
193
- export declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>>;
194
-
195
- export declare interface Ref<T = any> {
196
- value: T;
197
- /**
198
- * Type differentiator only.
199
- * We need this to be in public d.ts but don't want it to show up in IDE
200
- * autocomplete, so we use a private Symbol instead.
201
- */
202
- [RefSymbol]: true;
203
- }
204
-
205
- export declare function ref<T extends object>(value: T): [T] extends [Ref] ? T : Ref<UnwrapRef<T>>;
206
-
207
- export declare function ref<T>(value: T): Ref<UnwrapRef<T>>;
208
-
209
- export declare function ref<T = any>(): Ref<T | undefined>;
210
-
211
- declare const RefSymbol: unique symbol;
212
-
213
- /**
214
- * This is a special exported interface for other packages to declare
215
- * additional types that should bail out for ref unwrapping. For example
216
- * \@vue/runtime-dom can declare it like so in its d.ts:
217
- *
218
- * ``` ts
219
- * declare module '@vue/reactivity' {
220
- * export interface RefUnwrapBailTypes {
221
- * runtimeDOMBailTypes: Node | Window
222
- * }
223
- * }
224
- * ```
225
- *
226
- * Note that api-extractor somehow refuses to include `declare module`
227
- * augmentations in its generated d.ts, so we have to manually append them
228
- * to the final generated d.ts in our build process.
229
- */
230
- export declare interface RefUnwrapBailTypes {
231
- }
232
-
233
- export declare function resetTracking(): void;
234
-
235
- export declare type ShallowReactive<T> = T & {
236
- [ShallowReactiveMarker]?: true;
237
- };
238
-
239
- /**
240
- * Return a shallowly-reactive copy of the original object, where only the root
241
- * level properties are reactive. It also does not auto-unwrap refs (even at the
242
- * root level).
243
- */
244
- export declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
245
-
246
- declare const ShallowReactiveMarker: unique symbol;
247
-
248
- /**
249
- * Returns a reactive-copy of the original object, where only the root level
250
- * properties are readonly, and does NOT unwrap refs nor recursively convert
251
- * returned properties.
252
- * This is used for creating the props proxy object for stateful components.
253
- */
254
- export declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
255
-
256
- export declare type ShallowRef<T = any> = Ref<T> & {
257
- [ShallowRefMarker]?: true;
258
- };
259
-
260
- export declare function shallowRef<T extends object>(value: T): T extends Ref ? T : ShallowRef<T>;
261
-
262
- export declare function shallowRef<T>(value: T): ShallowRef<T>;
263
-
264
- export declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
265
-
266
- declare const ShallowRefMarker: unique symbol;
267
-
268
- export declare type ShallowUnwrapRef<T> = {
269
- [K in keyof T]: T[K] extends Ref<infer V> ? V : T[K] extends Ref<infer V> | undefined ? unknown extends V ? undefined : V | undefined : T[K];
270
- };
271
-
272
- declare function stop_2(runner: ReactiveEffectRunner): void;
273
- export { stop_2 as stop }
274
-
275
- export declare function toRaw<T>(observed: T): T;
276
-
277
- export declare type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>;
278
-
279
- export declare function toRef<T extends object, K extends keyof T>(object: T, key: K): ToRef<T[K]>;
280
-
281
- export declare function toRef<T extends object, K extends keyof T>(object: T, key: K, defaultValue: T[K]): ToRef<Exclude<T[K], undefined>>;
282
-
283
- export declare type ToRefs<T = any> = {
284
- [K in keyof T]: ToRef<T[K]>;
285
- };
286
-
287
- export declare function toRefs<T extends object>(object: T): ToRefs<T>;
288
-
289
- export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
290
-
291
- /**
292
- * wasTracked and newTracked maintain the status for several levels of effect
293
- * tracking recursion. One bit per level is used to define whether the dependency
294
- * was/is tracked.
295
- */
296
- declare type TrackedMarkers = {
297
- /**
298
- * wasTracked
299
- */
300
- w: number;
301
- /**
302
- * newTracked
303
- */
304
- n: number;
305
- };
306
-
307
- export declare const enum TrackOpTypes {
308
- GET = "get",
309
- HAS = "has",
310
- ITERATE = "iterate"
311
- }
312
-
313
- export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
314
-
315
- export declare const enum TriggerOpTypes {
316
- SET = "set",
317
- ADD = "add",
318
- DELETE = "delete",
319
- CLEAR = "clear"
320
- }
321
-
322
- export declare function triggerRef(ref: Ref): void;
323
-
324
- export declare function unref<T>(ref: T | Ref<T>): T;
325
-
326
- export declare type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
327
-
328
- export declare type UnwrapRef<T> = T extends ShallowRef<infer V> ? V : T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
329
-
330
- declare type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
331
- [RawSymbol]?: true;
332
- } ? T : T extends ReadonlyArray<any> ? {
333
- [K in keyof T]: UnwrapRefSimple<T[K]>;
334
- } : T extends object & {
335
- [ShallowReactiveMarker]?: never;
336
- } ? {
337
- [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>;
338
- } : T;
339
-
340
- declare type WeakCollections = WeakMap<any, any> | WeakSet<any>;
341
-
342
- export declare interface WritableComputedOptions<T> {
343
- get: ComputedGetter<T>;
344
- set: ComputedSetter<T>;
345
- }
346
-
347
- export declare interface WritableComputedRef<T> extends Ref<T> {
348
- readonly effect: ReactiveEffect<T>;
349
- }
350
-
351
- export { }
1
+ import { IfAny } from '@vue/shared';
2
+
3
+ export declare const enum ReactiveFlags {
4
+ SKIP = "__v_skip",
5
+ IS_REACTIVE = "__v_isReactive",
6
+ IS_READONLY = "__v_isReadonly",
7
+ IS_SHALLOW = "__v_isShallow",
8
+ RAW = "__v_raw"
9
+ }
10
+ export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
11
+ /**
12
+ * Returns a reactive proxy of the object.
13
+ *
14
+ * The reactive conversion is "deep": it affects all nested properties. A
15
+ * reactive object also deeply unwraps any properties that are refs while
16
+ * maintaining reactivity.
17
+ *
18
+ * @example
19
+ * ```js
20
+ * const obj = reactive({ count: 0 })
21
+ * ```
22
+ *
23
+ * @param target - The source object.
24
+ * @see {@link https://vuejs.org/api/reactivity-core.html#reactive}
25
+ */
26
+ export declare function reactive<T extends object>(target: T): UnwrapNestedRefs<T>;
27
+ declare const ShallowReactiveMarker: unique symbol;
28
+ export type ShallowReactive<T> = T & {
29
+ [ShallowReactiveMarker]?: true;
30
+ };
31
+ /**
32
+ * Shallow version of {@link reactive()}.
33
+ *
34
+ * Unlike {@link reactive()}, there is no deep conversion: only root-level
35
+ * properties are reactive for a shallow reactive object. Property values are
36
+ * stored and exposed as-is - this also means properties with ref values will
37
+ * not be automatically unwrapped.
38
+ *
39
+ * @example
40
+ * ```js
41
+ * const state = shallowReactive({
42
+ * foo: 1,
43
+ * nested: {
44
+ * bar: 2
45
+ * }
46
+ * })
47
+ *
48
+ * // mutating state's own properties is reactive
49
+ * state.foo++
50
+ *
51
+ * // ...but does not convert nested objects
52
+ * isReactive(state.nested) // false
53
+ *
54
+ * // NOT reactive
55
+ * state.nested.bar++
56
+ * ```
57
+ *
58
+ * @param target - The source object.
59
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive}
60
+ */
61
+ export declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
62
+ type Primitive = string | number | boolean | bigint | symbol | undefined | null;
63
+ type Builtin = Primitive | Function | Date | Error | RegExp;
64
+ export type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends Ref<infer U> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? {
65
+ readonly [K in keyof T]: DeepReadonly<T[K]>;
66
+ } : Readonly<T>;
67
+ /**
68
+ * Takes an object (reactive or plain) or a ref and returns a readonly proxy to
69
+ * the original.
70
+ *
71
+ * A readonly proxy is deep: any nested property accessed will be readonly as
72
+ * well. It also has the same ref-unwrapping behavior as {@link reactive()},
73
+ * except the unwrapped values will also be made readonly.
74
+ *
75
+ * @example
76
+ * ```js
77
+ * const original = reactive({ count: 0 })
78
+ *
79
+ * const copy = readonly(original)
80
+ *
81
+ * watchEffect(() => {
82
+ * // works for reactivity tracking
83
+ * console.log(copy.count)
84
+ * })
85
+ *
86
+ * // mutating original will trigger watchers relying on the copy
87
+ * original.count++
88
+ *
89
+ * // mutating the copy will fail and result in a warning
90
+ * copy.count++ // warning!
91
+ * ```
92
+ *
93
+ * @param target - The source object.
94
+ * @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
95
+ */
96
+ export declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>>;
97
+ /**
98
+ * Shallow version of {@link readonly()}.
99
+ *
100
+ * Unlike {@link readonly()}, there is no deep conversion: only root-level
101
+ * properties are made readonly. Property values are stored and exposed as-is -
102
+ * this also means properties with ref values will not be automatically
103
+ * unwrapped.
104
+ *
105
+ * @example
106
+ * ```js
107
+ * const state = shallowReadonly({
108
+ * foo: 1,
109
+ * nested: {
110
+ * bar: 2
111
+ * }
112
+ * })
113
+ *
114
+ * // mutating state's own properties will fail
115
+ * state.foo++
116
+ *
117
+ * // ...but works on nested objects
118
+ * isReadonly(state.nested) // false
119
+ *
120
+ * // works
121
+ * state.nested.bar++
122
+ * ```
123
+ *
124
+ * @param target - The source object.
125
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly}
126
+ */
127
+ export declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
128
+ /**
129
+ * Checks if an object is a proxy created by {@link reactive()} or
130
+ * {@link shallowReactive()} (or {@link ref()} in some cases).
131
+ *
132
+ * @example
133
+ * ```js
134
+ * isReactive(reactive({})) // => true
135
+ * isReactive(readonly(reactive({}))) // => true
136
+ * isReactive(ref({}).value) // => true
137
+ * isReactive(readonly(ref({})).value) // => true
138
+ * isReactive(ref(true)) // => false
139
+ * isReactive(shallowRef({}).value) // => false
140
+ * isReactive(shallowReactive({})) // => true
141
+ * ```
142
+ *
143
+ * @param value - The value to check.
144
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
145
+ */
146
+ export declare function isReactive(value: unknown): boolean;
147
+ /**
148
+ * Checks whether the passed value is a readonly object. The properties of a
149
+ * readonly object can change, but they can't be assigned directly via the
150
+ * passed object.
151
+ *
152
+ * The proxies created by {@link readonly()} and {@link shallowReadonly()} are
153
+ * both considered readonly, as is a computed ref without a set function.
154
+ *
155
+ * @param value - The value to check.
156
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
157
+ */
158
+ export declare function isReadonly(value: unknown): boolean;
159
+ export declare function isShallow(value: unknown): boolean;
160
+ /**
161
+ * Checks if an object is a proxy created by {@link reactive},
162
+ * {@link readonly}, {@link shallowReactive} or {@link shallowReadonly()}.
163
+ *
164
+ * @param value - The value to check.
165
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
166
+ */
167
+ export declare function isProxy(value: unknown): boolean;
168
+ /**
169
+ * Returns the raw, original object of a Vue-created proxy.
170
+ *
171
+ * `toRaw()` can return the original object from proxies created by
172
+ * {@link reactive()}, {@link readonly()}, {@link shallowReactive()} or
173
+ * {@link shallowReadonly()}.
174
+ *
175
+ * This is an escape hatch that can be used to temporarily read without
176
+ * incurring proxy access / tracking overhead or write without triggering
177
+ * changes. It is **not** recommended to hold a persistent reference to the
178
+ * original object. Use with caution.
179
+ *
180
+ * @example
181
+ * ```js
182
+ * const foo = {}
183
+ * const reactiveFoo = reactive(foo)
184
+ *
185
+ * console.log(toRaw(reactiveFoo) === foo) // true
186
+ * ```
187
+ *
188
+ * @param observed - The object for which the "raw" value is requested.
189
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
190
+ */
191
+ export declare function toRaw<T>(observed: T): T;
192
+ export type Raw<T> = T & {
193
+ [RawSymbol]?: true;
194
+ };
195
+ /**
196
+ * Marks an object so that it will never be converted to a proxy. Returns the
197
+ * object itself.
198
+ *
199
+ * @example
200
+ * ```js
201
+ * const foo = markRaw({})
202
+ * console.log(isReactive(reactive(foo))) // false
203
+ *
204
+ * // also works when nested inside other reactive objects
205
+ * const bar = reactive({ foo })
206
+ * console.log(isReactive(bar.foo)) // false
207
+ * ```
208
+ *
209
+ * **Warning:** `markRaw()` together with the shallow APIs such as
210
+ * {@link shallowReactive()} allow you to selectively opt-out of the default
211
+ * deep reactive/readonly conversion and embed raw, non-proxied objects in your
212
+ * state graph.
213
+ *
214
+ * @param value - The object to be marked as "raw".
215
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
216
+ */
217
+ export declare function markRaw<T extends object>(value: T): Raw<T>;
218
+
219
+ type CollectionTypes = IterableCollections | WeakCollections;
220
+ type IterableCollections = Map<any, any> | Set<any>;
221
+ type WeakCollections = WeakMap<any, any> | WeakSet<any>;
222
+
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
+ export declare class EffectScope {
236
+ detached: boolean;
237
+ /* removed internal: _active */
238
+ /* removed internal: effects */
239
+ /* removed internal: cleanups */
240
+ /* removed internal: parent */
241
+ /* removed internal: scopes */
242
+ /* removed internal: index */
243
+ constructor(detached?: boolean);
244
+ get active(): boolean;
245
+ run<T>(fn: () => T): T | undefined;
246
+ /* removed internal: on */
247
+ /* removed internal: off */
248
+ stop(fromParent?: boolean): void;
249
+ }
250
+ /**
251
+ * Creates an effect scope object which can capture the reactive effects (i.e.
252
+ * computed and watchers) created within it so that these effects can be
253
+ * disposed together. For detailed use cases of this API, please consult its
254
+ * corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
255
+ *
256
+ * @param detached - Can be used to create a "detached" effect scope.
257
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
258
+ */
259
+ export declare function effectScope(detached?: boolean): EffectScope;
260
+ /**
261
+ * Returns the current active effect scope if there is one.
262
+ *
263
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
264
+ */
265
+ export declare function getCurrentScope(): EffectScope | undefined;
266
+ /**
267
+ * Registers a dispose callback on the current active effect scope. The
268
+ * callback will be invoked when the associated effect scope is stopped.
269
+ *
270
+ * @param fn - The callback function to attach to the scope's cleanup.
271
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
272
+ */
273
+ export declare function onScopeDispose(fn: () => void): void;
274
+
275
+ declare const ComputedRefSymbol: unique symbol;
276
+ export interface ComputedRef<T = any> extends WritableComputedRef<T> {
277
+ readonly value: T;
278
+ [ComputedRefSymbol]: true;
279
+ }
280
+ export interface WritableComputedRef<T> extends Ref<T> {
281
+ readonly effect: ReactiveEffect<T>;
282
+ }
283
+ export type ComputedGetter<T> = (...args: any[]) => T;
284
+ export type ComputedSetter<T> = (v: T) => void;
285
+ export interface WritableComputedOptions<T> {
286
+ get: ComputedGetter<T>;
287
+ set: ComputedSetter<T>;
288
+ }
289
+ declare class ComputedRefImpl<T> {
290
+ private readonly _setter;
291
+ dep?: Dep;
292
+ private _value;
293
+ readonly effect: ReactiveEffect<T>;
294
+ readonly __v_isRef = true;
295
+ readonly [ReactiveFlags.IS_READONLY]: boolean;
296
+ _dirty: boolean;
297
+ _cacheable: boolean;
298
+ constructor(getter: ComputedGetter<T>, _setter: ComputedSetter<T>, isReadonly: boolean, isSSR: boolean);
299
+ get value(): T;
300
+ set value(newValue: T);
301
+ }
302
+ /**
303
+ * Takes a getter function and returns a readonly reactive ref object for the
304
+ * returned value from the getter. It can also take an object with get and set
305
+ * functions to create a writable ref object.
306
+ *
307
+ * @example
308
+ * ```js
309
+ * // Creating a readonly computed ref:
310
+ * const count = ref(1)
311
+ * const plusOne = computed(() => count.value + 1)
312
+ *
313
+ * console.log(plusOne.value) // 2
314
+ * plusOne.value++ // error
315
+ * ```
316
+ *
317
+ * ```js
318
+ * // Creating a writable computed ref:
319
+ * const count = ref(1)
320
+ * const plusOne = computed({
321
+ * get: () => count.value + 1,
322
+ * set: (val) => {
323
+ * count.value = val - 1
324
+ * }
325
+ * })
326
+ *
327
+ * plusOne.value = 1
328
+ * console.log(count.value) // 0
329
+ * ```
330
+ *
331
+ * @param getter - Function that produces the next value.
332
+ * @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
333
+ * @see {@link https://vuejs.org/api/reactivity-core.html#computed}
334
+ */
335
+ export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
336
+ export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
337
+
338
+ export type EffectScheduler = (...args: any[]) => any;
339
+ export type DebuggerEvent = {
340
+ effect: ReactiveEffect;
341
+ } & DebuggerEventExtraInfo;
342
+ export type DebuggerEventExtraInfo = {
343
+ target: object;
344
+ type: TrackOpTypes | TriggerOpTypes;
345
+ key: any;
346
+ newValue?: any;
347
+ oldValue?: any;
348
+ oldTarget?: Map<any, any> | Set<any>;
349
+ };
350
+ export declare const ITERATE_KEY: unique symbol;
351
+ export declare class ReactiveEffect<T = any> {
352
+ fn: () => T;
353
+ scheduler: EffectScheduler | null;
354
+ active: boolean;
355
+ deps: Dep[];
356
+ parent: ReactiveEffect | undefined;
357
+ /* removed internal: computed */
358
+ /* removed internal: allowRecurse */
359
+ /* removed internal: deferStop */
360
+ onStop?: () => void;
361
+ onTrack?: (event: DebuggerEvent) => void;
362
+ onTrigger?: (event: DebuggerEvent) => void;
363
+ constructor(fn: () => T, scheduler?: EffectScheduler | null, scope?: EffectScope);
364
+ run(): T | undefined;
365
+ stop(): void;
366
+ }
367
+ export interface DebuggerOptions {
368
+ onTrack?: (event: DebuggerEvent) => void;
369
+ onTrigger?: (event: DebuggerEvent) => void;
370
+ }
371
+ export interface ReactiveEffectOptions extends DebuggerOptions {
372
+ lazy?: boolean;
373
+ scheduler?: EffectScheduler;
374
+ scope?: EffectScope;
375
+ allowRecurse?: boolean;
376
+ onStop?: () => void;
377
+ }
378
+ export interface ReactiveEffectRunner<T = any> {
379
+ (): T;
380
+ effect: ReactiveEffect;
381
+ }
382
+ /**
383
+ * Registers the given function to track reactive updates.
384
+ *
385
+ * The given function will be run once immediately. Every time any reactive
386
+ * property that's accessed within it gets updated, the function will run again.
387
+ *
388
+ * @param fn - The function that will track reactive updates.
389
+ * @param options - Allows to control the effect's behaviour.
390
+ * @returns A runner that can be used to control the effect after creation.
391
+ */
392
+ export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner;
393
+ /**
394
+ * Stops the effect associated with the given runner.
395
+ *
396
+ * @param runner - Association with the effect to stop tracking.
397
+ */
398
+ export declare function stop(runner: ReactiveEffectRunner): void;
399
+ /**
400
+ * Temporarily pauses tracking.
401
+ */
402
+ export declare function pauseTracking(): void;
403
+ /**
404
+ * Re-enables effect tracking (if it was paused).
405
+ */
406
+ export declare function enableTracking(): void;
407
+ /**
408
+ * Resets the previous global effect tracking state.
409
+ */
410
+ export declare function resetTracking(): void;
411
+ /**
412
+ * Tracks access to a reactive property.
413
+ *
414
+ * This will check which effect is running at the moment and record it as dep
415
+ * which records all effects that depend on the reactive property.
416
+ *
417
+ * @param target - Object holding the reactive property.
418
+ * @param type - Defines the type of access to the reactive property.
419
+ * @param key - Identifier of the reactive property to track.
420
+ */
421
+ export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
422
+ /**
423
+ * Finds all deps associated with the target (or a specific property) and
424
+ * triggers the effects stored within.
425
+ *
426
+ * @param target - The reactive object.
427
+ * @param type - Defines the type of the operation that needs to trigger effects.
428
+ * @param key - Can be used to target a specific reactive property in the target object.
429
+ */
430
+ export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
431
+
432
+ type Dep = Set<ReactiveEffect> & TrackedMarkers;
433
+ /**
434
+ * wasTracked and newTracked maintain the status for several levels of effect
435
+ * tracking recursion. One bit per level is used to define whether the dependency
436
+ * was/is tracked.
437
+ */
438
+ type TrackedMarkers = {
439
+ /**
440
+ * wasTracked
441
+ */
442
+ w: number;
443
+ /**
444
+ * newTracked
445
+ */
446
+ n: number;
447
+ };
448
+
449
+ declare const RefSymbol: unique symbol;
450
+ declare const RawSymbol: unique symbol;
451
+ export interface Ref<T = any> {
452
+ value: T;
453
+ /**
454
+ * Type differentiator only.
455
+ * We need this to be in public d.ts but don't want it to show up in IDE
456
+ * autocomplete, so we use a private Symbol instead.
457
+ */
458
+ [RefSymbol]: true;
459
+ }
460
+ /**
461
+ * Checks if a value is a ref object.
462
+ *
463
+ * @param r - The value to inspect.
464
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isref}
465
+ */
466
+ export declare function isRef<T>(r: Ref<T> | unknown): r is Ref<T>;
467
+ /**
468
+ * Takes an inner value and returns a reactive and mutable ref object, which
469
+ * has a single property `.value` that points to the inner value.
470
+ *
471
+ * @param value - The object to wrap in the ref.
472
+ * @see {@link https://vuejs.org/api/reactivity-core.html#ref}
473
+ */
474
+ export declare function ref<T extends Ref>(value: T): T;
475
+ export declare function ref<T>(value: T): Ref<UnwrapRef<T>>;
476
+ export declare function ref<T = any>(): Ref<T | undefined>;
477
+ declare const ShallowRefMarker: unique symbol;
478
+ export type ShallowRef<T = any> = Ref<T> & {
479
+ [ShallowRefMarker]?: true;
480
+ };
481
+ /**
482
+ * Shallow version of {@link ref()}.
483
+ *
484
+ * @example
485
+ * ```js
486
+ * const state = shallowRef({ count: 1 })
487
+ *
488
+ * // does NOT trigger change
489
+ * state.value.count = 2
490
+ *
491
+ * // does trigger change
492
+ * state.value = { count: 2 }
493
+ * ```
494
+ *
495
+ * @param value - The "inner value" for the shallow ref.
496
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowref}
497
+ */
498
+ export declare function shallowRef<T extends object>(value: T): T extends Ref ? T : ShallowRef<T>;
499
+ export declare function shallowRef<T>(value: T): ShallowRef<T>;
500
+ export declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
501
+ /**
502
+ * Force trigger effects that depends on a shallow ref. This is typically used
503
+ * after making deep mutations to the inner value of a shallow ref.
504
+ *
505
+ * @example
506
+ * ```js
507
+ * const shallow = shallowRef({
508
+ * greet: 'Hello, world'
509
+ * })
510
+ *
511
+ * // Logs "Hello, world" once for the first run-through
512
+ * watchEffect(() => {
513
+ * console.log(shallow.value.greet)
514
+ * })
515
+ *
516
+ * // This won't trigger the effect because the ref is shallow
517
+ * shallow.value.greet = 'Hello, universe'
518
+ *
519
+ * // Logs "Hello, universe"
520
+ * triggerRef(shallow)
521
+ * ```
522
+ *
523
+ * @param ref - The ref whose tied effects shall be executed.
524
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
525
+ */
526
+ export declare function triggerRef(ref: Ref): void;
527
+ export type MaybeRef<T = any> = T | Ref<T>;
528
+ export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T);
529
+ /**
530
+ * Returns the inner value if the argument is a ref, otherwise return the
531
+ * argument itself. This is a sugar function for
532
+ * `val = isRef(val) ? val.value : val`.
533
+ *
534
+ * @example
535
+ * ```js
536
+ * function useFoo(x: number | Ref<number>) {
537
+ * const unwrapped = unref(x)
538
+ * // unwrapped is guaranteed to be number now
539
+ * }
540
+ * ```
541
+ *
542
+ * @param ref - Ref or plain value to be converted into the plain value.
543
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
544
+ */
545
+ export declare function unref<T>(ref: MaybeRef<T>): T;
546
+ /**
547
+ * Normalizes values / refs / getters to values.
548
+ * This is similar to {@link unref()}, except that it also normalizes getters.
549
+ * If the argument is a getter, it will be invoked and its return value will
550
+ * be returned.
551
+ *
552
+ * @example
553
+ * ```js
554
+ * toValue(1) // 1
555
+ * toValue(ref(1)) // 1
556
+ * toValue(() => 1) // 1
557
+ * ```
558
+ *
559
+ * @param source - A getter, an existing ref, or a non-function value.
560
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
561
+ */
562
+ export declare function toValue<T>(source: MaybeRefOrGetter<T>): T;
563
+ /**
564
+ * Returns a reactive proxy for the given object.
565
+ *
566
+ * If the object already is reactive, it's returned as-is. If not, a new
567
+ * reactive proxy is created. Direct child properties that are refs are properly
568
+ * handled, as well.
569
+ *
570
+ * @param objectWithRefs - Either an already-reactive object or a simple object
571
+ * that contains refs.
572
+ */
573
+ export declare function proxyRefs<T extends object>(objectWithRefs: T): ShallowUnwrapRef<T>;
574
+ export type CustomRefFactory<T> = (track: () => void, trigger: () => void) => {
575
+ get: () => T;
576
+ set: (value: T) => void;
577
+ };
578
+ /**
579
+ * Creates a customized ref with explicit control over its dependency tracking
580
+ * and updates triggering.
581
+ *
582
+ * @param factory - The function that receives the `track` and `trigger` callbacks.
583
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#customref}
584
+ */
585
+ export declare function customRef<T>(factory: CustomRefFactory<T>): Ref<T>;
586
+ export type ToRefs<T = any> = {
587
+ [K in keyof T]: ToRef<T[K]>;
588
+ };
589
+ /**
590
+ * Converts a reactive object to a plain object where each property of the
591
+ * resulting object is a ref pointing to the corresponding property of the
592
+ * original object. Each individual ref is created using {@link toRef()}.
593
+ *
594
+ * @param object - Reactive object to be made into an object of linked refs.
595
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
596
+ */
597
+ export declare function toRefs<T extends object>(object: T): ToRefs<T>;
598
+ export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>;
599
+ /**
600
+ * Used to normalize values / refs / getters into refs.
601
+ *
602
+ * @example
603
+ * ```js
604
+ * // returns existing refs as-is
605
+ * toRef(existingRef)
606
+ *
607
+ * // creates a ref that calls the getter on .value access
608
+ * toRef(() => props.foo)
609
+ *
610
+ * // creates normal refs from non-function values
611
+ * // equivalent to ref(1)
612
+ * toRef(1)
613
+ * ```
614
+ *
615
+ * Can also be used to create a ref for a property on a source reactive object.
616
+ * The created ref is synced with its source property: mutating the source
617
+ * property will update the ref, and vice-versa.
618
+ *
619
+ * @example
620
+ * ```js
621
+ * const state = reactive({
622
+ * foo: 1,
623
+ * bar: 2
624
+ * })
625
+ *
626
+ * const fooRef = toRef(state, 'foo')
627
+ *
628
+ * // mutating the ref updates the original
629
+ * fooRef.value++
630
+ * console.log(state.foo) // 2
631
+ *
632
+ * // mutating the original also updates the ref
633
+ * state.foo++
634
+ * console.log(fooRef.value) // 3
635
+ * ```
636
+ *
637
+ * @param source - A getter, an existing ref, a non-function value, or a
638
+ * reactive object to create a property ref from.
639
+ * @param [key] - (optional) Name of the property in the reactive object.
640
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#toref}
641
+ */
642
+ export declare function toRef<T>(value: T): T extends () => infer R ? Readonly<Ref<R>> : T extends Ref ? T : Ref<UnwrapRef<T>>;
643
+ export declare function toRef<T extends object, K extends keyof T>(object: T, key: K): ToRef<T[K]>;
644
+ export declare function toRef<T extends object, K extends keyof T>(object: T, key: K, defaultValue: T[K]): ToRef<Exclude<T[K], undefined>>;
645
+ type BaseTypes = string | number | boolean;
646
+ /**
647
+ * This is a special exported interface for other packages to declare
648
+ * additional types that should bail out for ref unwrapping. For example
649
+ * \@vue/runtime-dom can declare it like so in its d.ts:
650
+ *
651
+ * ``` ts
652
+ * declare module '@vue/reactivity' {
653
+ * export interface RefUnwrapBailTypes {
654
+ * runtimeDOMBailTypes: Node | Window
655
+ * }
656
+ * }
657
+ * ```
658
+ */
659
+ export interface RefUnwrapBailTypes {
660
+ }
661
+ export type ShallowUnwrapRef<T> = {
662
+ [K in keyof T]: T[K] extends Ref<infer V> ? V : T[K] extends Ref<infer V> | undefined ? unknown extends V ? undefined : V | undefined : T[K];
663
+ };
664
+ export type UnwrapRef<T> = T extends ShallowRef<infer V> ? V : T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
665
+ type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
666
+ [RawSymbol]?: true;
667
+ } ? T : T extends ReadonlyArray<any> ? {
668
+ [K in keyof T]: UnwrapRefSimple<T[K]>;
669
+ } : T extends object & {
670
+ [ShallowReactiveMarker]?: never;
671
+ } ? {
672
+ [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>;
673
+ } : T;
674
+
675
+ export declare function deferredComputed<T>(getter: () => T): ComputedRef<T>;
676
+