@vue/reactivity 3.6.0-rc.4 → 3.6.0-rc.6
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.
- package/dist/reactivity.cjs.js +64 -59
- package/dist/reactivity.cjs.prod.js +62 -57
- package/dist/reactivity.d.ts +466 -467
- package/dist/reactivity.esm-browser.js +65 -60
- package/dist/reactivity.esm-browser.prod.js +2 -2
- package/dist/reactivity.esm-bundler.js +64 -59
- package/dist/reactivity.global.js +65 -60
- package/dist/reactivity.global.prod.js +2 -2
- package/package.json +2 -2
package/dist/reactivity.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IfAny } from "@vue/shared";
|
|
2
|
-
|
|
3
2
|
//#region temp/packages/reactivity/src/constants.d.ts
|
|
4
3
|
export declare enum TrackOpTypes {
|
|
5
4
|
GET = "get",
|
|
@@ -32,36 +31,36 @@ export declare class EffectScope implements ReactiveNode {
|
|
|
32
31
|
get active(): boolean;
|
|
33
32
|
pause(): void;
|
|
34
33
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
* Resumes the effect scope, including all child scopes and effects.
|
|
35
|
+
*/
|
|
37
36
|
resume(): void;
|
|
38
37
|
run<T>(fn: () => T): T | undefined;
|
|
39
38
|
stop(): void;
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
|
-
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
43
|
-
* computed and watchers) created within it so that these effects can be
|
|
44
|
-
* disposed together. For detailed use cases of this API, please consult its
|
|
45
|
-
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
46
|
-
*
|
|
47
|
-
* @param detached - Can be used to create a "detached" effect scope.
|
|
48
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
|
|
49
|
-
*/
|
|
41
|
+
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
42
|
+
* computed and watchers) created within it so that these effects can be
|
|
43
|
+
* disposed together. For detailed use cases of this API, please consult its
|
|
44
|
+
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
45
|
+
*
|
|
46
|
+
* @param detached - Can be used to create a "detached" effect scope.
|
|
47
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
|
|
48
|
+
*/
|
|
50
49
|
export declare function effectScope(detached?: boolean): EffectScope;
|
|
51
50
|
/**
|
|
52
|
-
* Returns the current active effect scope if there is one.
|
|
53
|
-
*
|
|
54
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
55
|
-
*/
|
|
51
|
+
* Returns the current active effect scope if there is one.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
54
|
+
*/
|
|
56
55
|
export declare function getCurrentScope(): EffectScope | undefined;
|
|
57
56
|
export declare function setCurrentScope(scope?: EffectScope): EffectScope | undefined;
|
|
58
57
|
/**
|
|
59
|
-
* Registers a dispose callback on the current active effect scope. The
|
|
60
|
-
* callback will be invoked when the associated effect scope is stopped.
|
|
61
|
-
*
|
|
62
|
-
* @param fn - The callback function to attach to the scope's cleanup.
|
|
63
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
64
|
-
*/
|
|
58
|
+
* Registers a dispose callback on the current active effect scope. The
|
|
59
|
+
* callback will be invoked when the associated effect scope is stopped.
|
|
60
|
+
*
|
|
61
|
+
* @param fn - The callback function to attach to the scope's cleanup.
|
|
62
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
63
|
+
*/
|
|
65
64
|
export declare function onScopeDispose(fn: () => void, failSilently?: boolean): void;
|
|
66
65
|
//#endregion
|
|
67
66
|
//#region temp/packages/reactivity/src/system.d.ts
|
|
@@ -118,8 +117,8 @@ export interface ReactiveEffectRunner<T = any> {
|
|
|
118
117
|
}
|
|
119
118
|
export declare enum EffectFlags {
|
|
120
119
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
* ReactiveEffect only
|
|
121
|
+
*/
|
|
123
122
|
ALLOW_RECURSE = 128,
|
|
124
123
|
PAUSED = 256,
|
|
125
124
|
STOP = 1024
|
|
@@ -144,35 +143,35 @@ export declare class ReactiveEffect<T = any> implements ReactiveEffectOptions, R
|
|
|
144
143
|
}
|
|
145
144
|
export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner<T>;
|
|
146
145
|
/**
|
|
147
|
-
* Stops the effect associated with the given runner.
|
|
148
|
-
*
|
|
149
|
-
* @param runner - Association with the effect to stop tracking.
|
|
150
|
-
*/
|
|
146
|
+
* Stops the effect associated with the given runner.
|
|
147
|
+
*
|
|
148
|
+
* @param runner - Association with the effect to stop tracking.
|
|
149
|
+
*/
|
|
151
150
|
export declare function stop(runner: ReactiveEffectRunner): void;
|
|
152
151
|
/**
|
|
153
|
-
* Temporarily pauses tracking.
|
|
154
|
-
*/
|
|
152
|
+
* Temporarily pauses tracking.
|
|
153
|
+
*/
|
|
155
154
|
export declare function pauseTracking(): void;
|
|
156
155
|
/**
|
|
157
|
-
* Re-enables effect tracking (if it was paused).
|
|
158
|
-
*/
|
|
156
|
+
* Re-enables effect tracking (if it was paused).
|
|
157
|
+
*/
|
|
159
158
|
export declare function enableTracking(): void;
|
|
160
159
|
/**
|
|
161
|
-
* Resets the previous global effect tracking state.
|
|
162
|
-
*/
|
|
160
|
+
* Resets the previous global effect tracking state.
|
|
161
|
+
*/
|
|
163
162
|
export declare function resetTracking(): void;
|
|
164
163
|
/**
|
|
165
|
-
* Registers a cleanup function for the current active effect.
|
|
166
|
-
* The cleanup function is called right before the next effect run, or when the
|
|
167
|
-
* effect is stopped.
|
|
168
|
-
*
|
|
169
|
-
* Throws a warning if there is no current active effect. The warning can be
|
|
170
|
-
* suppressed by passing `true` to the second argument.
|
|
171
|
-
*
|
|
172
|
-
* @param fn - the cleanup function to be registered
|
|
173
|
-
* @param failSilently - if `true`, will not throw warning when called without
|
|
174
|
-
* an active effect.
|
|
175
|
-
*/
|
|
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
|
+
*/
|
|
176
175
|
export declare function onEffectCleanup(fn: () => void, failSilently?: boolean): void;
|
|
177
176
|
//#endregion
|
|
178
177
|
//#region temp/packages/reactivity/src/computed.d.ts
|
|
@@ -181,8 +180,8 @@ declare const WritableComputedRefSymbol: unique symbol;
|
|
|
181
180
|
interface BaseComputedRef<T, S = T> extends Ref<T, S> {
|
|
182
181
|
[ComputedRefSymbol]: true;
|
|
183
182
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
* @deprecated computed no longer uses effect
|
|
184
|
+
*/
|
|
186
185
|
effect: ComputedRefImpl;
|
|
187
186
|
}
|
|
188
187
|
export interface ComputedRef<T = any> extends BaseComputedRef<T> {
|
|
@@ -198,9 +197,9 @@ export interface WritableComputedOptions<T, S = T> {
|
|
|
198
197
|
set: ComputedSetter<S>;
|
|
199
198
|
}
|
|
200
199
|
/**
|
|
201
|
-
* @private exported by @vue/reactivity for Vue core use, but not exported from
|
|
202
|
-
* the main vue package
|
|
203
|
-
*/
|
|
200
|
+
* @private exported by @vue/reactivity for Vue core use, but not exported from
|
|
201
|
+
* the main vue package
|
|
202
|
+
*/
|
|
204
203
|
export declare class ComputedRefImpl<T = any> implements ReactiveNode {
|
|
205
204
|
fn: ComputedGetter<T>;
|
|
206
205
|
private readonly setter;
|
|
@@ -219,38 +218,38 @@ export declare class ComputedRefImpl<T = any> implements ReactiveNode {
|
|
|
219
218
|
update(): boolean;
|
|
220
219
|
}
|
|
221
220
|
/**
|
|
222
|
-
* Takes a getter function and returns a readonly reactive ref object for the
|
|
223
|
-
* returned value from the getter. It can also take an object with get and set
|
|
224
|
-
* functions to create a writable ref object.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```js
|
|
228
|
-
* // Creating a readonly computed ref:
|
|
229
|
-
* const count = ref(1)
|
|
230
|
-
* const plusOne = computed(() => count.value + 1)
|
|
231
|
-
*
|
|
232
|
-
* console.log(plusOne.value) // 2
|
|
233
|
-
* plusOne.value++ // error
|
|
234
|
-
* ```
|
|
235
|
-
*
|
|
236
|
-
* ```js
|
|
237
|
-
* // Creating a writable computed ref:
|
|
238
|
-
* const count = ref(1)
|
|
239
|
-
* const plusOne = computed({
|
|
240
|
-
* get: () => count.value + 1,
|
|
241
|
-
* set: (val) => {
|
|
242
|
-
* count.value = val - 1
|
|
243
|
-
* }
|
|
244
|
-
* })
|
|
245
|
-
*
|
|
246
|
-
* plusOne.value = 1
|
|
247
|
-
* console.log(count.value) // 0
|
|
248
|
-
* ```
|
|
249
|
-
*
|
|
250
|
-
* @param getter - Function that produces the next value.
|
|
251
|
-
* @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
|
|
252
|
-
* @see {@link https://vuejs.org/api/reactivity-core.html#computed}
|
|
253
|
-
*/
|
|
221
|
+
* Takes a getter function and returns a readonly reactive ref object for the
|
|
222
|
+
* returned value from the getter. It can also take an object with get and set
|
|
223
|
+
* functions to create a writable ref object.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```js
|
|
227
|
+
* // Creating a readonly computed ref:
|
|
228
|
+
* const count = ref(1)
|
|
229
|
+
* const plusOne = computed(() => count.value + 1)
|
|
230
|
+
*
|
|
231
|
+
* console.log(plusOne.value) // 2
|
|
232
|
+
* plusOne.value++ // error
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* ```js
|
|
236
|
+
* // Creating a writable computed ref:
|
|
237
|
+
* const count = ref(1)
|
|
238
|
+
* const plusOne = computed({
|
|
239
|
+
* get: () => count.value + 1,
|
|
240
|
+
* set: (val) => {
|
|
241
|
+
* count.value = val - 1
|
|
242
|
+
* }
|
|
243
|
+
* })
|
|
244
|
+
*
|
|
245
|
+
* plusOne.value = 1
|
|
246
|
+
* console.log(count.value) // 0
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @param getter - Function that produces the next value.
|
|
250
|
+
* @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
|
|
251
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#computed}
|
|
252
|
+
*/
|
|
254
253
|
export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
|
|
255
254
|
export declare function computed<T, S = T>(options: WritableComputedOptions<T, S>, debugOptions?: DebuggerOptions): WritableComputedRef<T, S>;
|
|
256
255
|
//#endregion
|
|
@@ -262,20 +261,20 @@ export interface ReactiveMarker {
|
|
|
262
261
|
}
|
|
263
262
|
export type Reactive<T> = UnwrapNestedRefs<T> & (T extends readonly any[] ? ReactiveMarker : {});
|
|
264
263
|
/**
|
|
265
|
-
* Returns a reactive proxy of the object.
|
|
266
|
-
*
|
|
267
|
-
* The reactive conversion is "deep": it affects all nested properties. A
|
|
268
|
-
* reactive object also deeply unwraps any properties that are refs while
|
|
269
|
-
* maintaining reactivity.
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```js
|
|
273
|
-
* const obj = reactive({ count: 0 })
|
|
274
|
-
* ```
|
|
275
|
-
*
|
|
276
|
-
* @param target - The source object.
|
|
277
|
-
* @see {@link https://vuejs.org/api/reactivity-core.html#reactive}
|
|
278
|
-
*/
|
|
264
|
+
* Returns a reactive proxy of the object.
|
|
265
|
+
*
|
|
266
|
+
* The reactive conversion is "deep": it affects all nested properties. A
|
|
267
|
+
* reactive object also deeply unwraps any properties that are refs while
|
|
268
|
+
* maintaining reactivity.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```js
|
|
272
|
+
* const obj = reactive({ count: 0 })
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @param target - The source object.
|
|
276
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#reactive}
|
|
277
|
+
*/
|
|
279
278
|
export declare function reactive<T extends object>(target: T): Reactive<T>;
|
|
280
279
|
declare class ShallowReactiveBrandClass {
|
|
281
280
|
private __shallowReactiveBrand?;
|
|
@@ -283,205 +282,205 @@ declare class ShallowReactiveBrandClass {
|
|
|
283
282
|
type ShallowReactiveBrand = ShallowReactiveBrandClass;
|
|
284
283
|
export type ShallowReactive<T> = T & ShallowReactiveBrand;
|
|
285
284
|
/**
|
|
286
|
-
* Shallow version of {@link reactive}.
|
|
287
|
-
*
|
|
288
|
-
* Unlike {@link reactive}, there is no deep conversion: only root-level
|
|
289
|
-
* properties are reactive for a shallow reactive object. Property values are
|
|
290
|
-
* stored and exposed as-is - this also means properties with ref values will
|
|
291
|
-
* not be automatically unwrapped.
|
|
292
|
-
*
|
|
293
|
-
* @example
|
|
294
|
-
* ```js
|
|
295
|
-
* const state = shallowReactive({
|
|
296
|
-
* foo: 1,
|
|
297
|
-
* nested: {
|
|
298
|
-
* bar: 2
|
|
299
|
-
* }
|
|
300
|
-
* })
|
|
301
|
-
*
|
|
302
|
-
* // mutating state's own properties is reactive
|
|
303
|
-
* state.foo++
|
|
304
|
-
*
|
|
305
|
-
* // ...but does not convert nested objects
|
|
306
|
-
* isReactive(state.nested) // false
|
|
307
|
-
*
|
|
308
|
-
* // NOT reactive
|
|
309
|
-
* state.nested.bar++
|
|
310
|
-
* ```
|
|
311
|
-
*
|
|
312
|
-
* @param target - The source object.
|
|
313
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive}
|
|
314
|
-
*/
|
|
285
|
+
* Shallow version of {@link reactive}.
|
|
286
|
+
*
|
|
287
|
+
* Unlike {@link reactive}, there is no deep conversion: only root-level
|
|
288
|
+
* properties are reactive for a shallow reactive object. Property values are
|
|
289
|
+
* stored and exposed as-is - this also means properties with ref values will
|
|
290
|
+
* not be automatically unwrapped.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```js
|
|
294
|
+
* const state = shallowReactive({
|
|
295
|
+
* foo: 1,
|
|
296
|
+
* nested: {
|
|
297
|
+
* bar: 2
|
|
298
|
+
* }
|
|
299
|
+
* })
|
|
300
|
+
*
|
|
301
|
+
* // mutating state's own properties is reactive
|
|
302
|
+
* state.foo++
|
|
303
|
+
*
|
|
304
|
+
* // ...but does not convert nested objects
|
|
305
|
+
* isReactive(state.nested) // false
|
|
306
|
+
*
|
|
307
|
+
* // NOT reactive
|
|
308
|
+
* state.nested.bar++
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* @param target - The source object.
|
|
312
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive}
|
|
313
|
+
*/
|
|
315
314
|
export declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
|
|
316
315
|
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
317
316
|
type Builtin = Primitive | Function | Date | Error | RegExp;
|
|
318
|
-
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, unknown> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? { readonly [K in keyof T]: DeepReadonly<T[K]
|
|
319
|
-
/**
|
|
320
|
-
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
321
|
-
* the original.
|
|
322
|
-
*
|
|
323
|
-
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
324
|
-
* well. It also has the same ref-unwrapping behavior as {@link reactive},
|
|
325
|
-
* except the unwrapped values will also be made readonly.
|
|
326
|
-
*
|
|
327
|
-
* @example
|
|
328
|
-
* ```js
|
|
329
|
-
* const original = reactive({ count: 0 })
|
|
330
|
-
*
|
|
331
|
-
* const copy = readonly(original)
|
|
332
|
-
*
|
|
333
|
-
* watchEffect(() => {
|
|
334
|
-
* // works for reactivity tracking
|
|
335
|
-
* console.log(copy.count)
|
|
336
|
-
* })
|
|
337
|
-
*
|
|
338
|
-
* // mutating original will trigger watchers relying on the copy
|
|
339
|
-
* original.count++
|
|
340
|
-
*
|
|
341
|
-
* // mutating the copy will fail and result in a warning
|
|
342
|
-
* copy.count++ // warning!
|
|
343
|
-
* ```
|
|
344
|
-
*
|
|
345
|
-
* @param target - The source object.
|
|
346
|
-
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
|
|
347
|
-
*/
|
|
317
|
+
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, unknown> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : Readonly<T>;
|
|
318
|
+
/**
|
|
319
|
+
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
320
|
+
* the original.
|
|
321
|
+
*
|
|
322
|
+
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
323
|
+
* well. It also has the same ref-unwrapping behavior as {@link reactive},
|
|
324
|
+
* except the unwrapped values will also be made readonly.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```js
|
|
328
|
+
* const original = reactive({ count: 0 })
|
|
329
|
+
*
|
|
330
|
+
* const copy = readonly(original)
|
|
331
|
+
*
|
|
332
|
+
* watchEffect(() => {
|
|
333
|
+
* // works for reactivity tracking
|
|
334
|
+
* console.log(copy.count)
|
|
335
|
+
* })
|
|
336
|
+
*
|
|
337
|
+
* // mutating original will trigger watchers relying on the copy
|
|
338
|
+
* original.count++
|
|
339
|
+
*
|
|
340
|
+
* // mutating the copy will fail and result in a warning
|
|
341
|
+
* copy.count++ // warning!
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @param target - The source object.
|
|
345
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
|
|
346
|
+
*/
|
|
348
347
|
export declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>>;
|
|
349
348
|
/**
|
|
350
|
-
* Shallow version of {@link readonly}.
|
|
351
|
-
*
|
|
352
|
-
* Unlike {@link readonly}, there is no deep conversion: only root-level
|
|
353
|
-
* properties are made readonly. Property values are stored and exposed as-is -
|
|
354
|
-
* this also means properties with ref values will not be automatically
|
|
355
|
-
* unwrapped.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```js
|
|
359
|
-
* const state = shallowReadonly({
|
|
360
|
-
* foo: 1,
|
|
361
|
-
* nested: {
|
|
362
|
-
* bar: 2
|
|
363
|
-
* }
|
|
364
|
-
* })
|
|
365
|
-
*
|
|
366
|
-
* // mutating state's own properties will fail
|
|
367
|
-
* state.foo++
|
|
368
|
-
*
|
|
369
|
-
* // ...but works on nested objects
|
|
370
|
-
* isReadonly(state.nested) // false
|
|
371
|
-
*
|
|
372
|
-
* // works
|
|
373
|
-
* state.nested.bar++
|
|
374
|
-
* ```
|
|
375
|
-
*
|
|
376
|
-
* @param target - The source object.
|
|
377
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly}
|
|
378
|
-
*/
|
|
349
|
+
* Shallow version of {@link readonly}.
|
|
350
|
+
*
|
|
351
|
+
* Unlike {@link readonly}, there is no deep conversion: only root-level
|
|
352
|
+
* properties are made readonly. Property values are stored and exposed as-is -
|
|
353
|
+
* this also means properties with ref values will not be automatically
|
|
354
|
+
* unwrapped.
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```js
|
|
358
|
+
* const state = shallowReadonly({
|
|
359
|
+
* foo: 1,
|
|
360
|
+
* nested: {
|
|
361
|
+
* bar: 2
|
|
362
|
+
* }
|
|
363
|
+
* })
|
|
364
|
+
*
|
|
365
|
+
* // mutating state's own properties will fail
|
|
366
|
+
* state.foo++
|
|
367
|
+
*
|
|
368
|
+
* // ...but works on nested objects
|
|
369
|
+
* isReadonly(state.nested) // false
|
|
370
|
+
*
|
|
371
|
+
* // works
|
|
372
|
+
* state.nested.bar++
|
|
373
|
+
* ```
|
|
374
|
+
*
|
|
375
|
+
* @param target - The source object.
|
|
376
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly}
|
|
377
|
+
*/
|
|
379
378
|
export declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
|
|
380
379
|
/**
|
|
381
|
-
* Checks if an object is a proxy created by {@link reactive} or
|
|
382
|
-
* {@link shallowReactive} (or {@link ref} in some cases).
|
|
383
|
-
*
|
|
384
|
-
* @example
|
|
385
|
-
* ```js
|
|
386
|
-
* isReactive(reactive({})) // => true
|
|
387
|
-
* isReactive(readonly(reactive({}))) // => true
|
|
388
|
-
* isReactive(ref({}).value) // => true
|
|
389
|
-
* isReactive(readonly(ref({})).value) // => true
|
|
390
|
-
* isReactive(ref(true)) // => false
|
|
391
|
-
* isReactive(shallowRef({}).value) // => false
|
|
392
|
-
* isReactive(shallowReactive({})) // => true
|
|
393
|
-
* ```
|
|
394
|
-
*
|
|
395
|
-
* @param value - The value to check.
|
|
396
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
|
|
397
|
-
*/
|
|
380
|
+
* Checks if an object is a proxy created by {@link reactive} or
|
|
381
|
+
* {@link shallowReactive} (or {@link ref} in some cases).
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```js
|
|
385
|
+
* isReactive(reactive({})) // => true
|
|
386
|
+
* isReactive(readonly(reactive({}))) // => true
|
|
387
|
+
* isReactive(ref({}).value) // => true
|
|
388
|
+
* isReactive(readonly(ref({})).value) // => true
|
|
389
|
+
* isReactive(ref(true)) // => false
|
|
390
|
+
* isReactive(shallowRef({}).value) // => false
|
|
391
|
+
* isReactive(shallowReactive({})) // => true
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @param value - The value to check.
|
|
395
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
|
|
396
|
+
*/
|
|
398
397
|
export declare function isReactive(value: unknown): boolean;
|
|
399
398
|
/**
|
|
400
|
-
* Checks whether the passed value is a readonly object. The properties of a
|
|
401
|
-
* readonly object can change, but they can't be assigned directly via the
|
|
402
|
-
* passed object.
|
|
403
|
-
*
|
|
404
|
-
* The proxies created by {@link readonly} and {@link shallowReadonly} are
|
|
405
|
-
* both considered readonly, as is a computed ref without a set function.
|
|
406
|
-
*
|
|
407
|
-
* @param value - The value to check.
|
|
408
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
|
|
409
|
-
*/
|
|
399
|
+
* Checks whether the passed value is a readonly object. The properties of a
|
|
400
|
+
* readonly object can change, but they can't be assigned directly via the
|
|
401
|
+
* passed object.
|
|
402
|
+
*
|
|
403
|
+
* The proxies created by {@link readonly} and {@link shallowReadonly} are
|
|
404
|
+
* both considered readonly, as is a computed ref without a set function.
|
|
405
|
+
*
|
|
406
|
+
* @param value - The value to check.
|
|
407
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
|
|
408
|
+
*/
|
|
410
409
|
export declare function isReadonly(value: unknown): boolean;
|
|
411
410
|
export declare function isShallow(value: unknown): boolean;
|
|
412
411
|
/**
|
|
413
|
-
* Checks if an object is a proxy created by {@link reactive},
|
|
414
|
-
* {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
|
|
415
|
-
*
|
|
416
|
-
* @param value - The value to check.
|
|
417
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
|
|
418
|
-
*/
|
|
412
|
+
* Checks if an object is a proxy created by {@link reactive},
|
|
413
|
+
* {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
|
|
414
|
+
*
|
|
415
|
+
* @param value - The value to check.
|
|
416
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
|
|
417
|
+
*/
|
|
419
418
|
export declare function isProxy(value: any): boolean;
|
|
420
419
|
/**
|
|
421
|
-
* Returns the raw, original object of a Vue-created proxy.
|
|
422
|
-
*
|
|
423
|
-
* `toRaw()` can return the original object from proxies created by
|
|
424
|
-
* {@link reactive}, {@link readonly}, {@link shallowReactive} or
|
|
425
|
-
* {@link shallowReadonly}.
|
|
426
|
-
*
|
|
427
|
-
* This is an escape hatch that can be used to temporarily read without
|
|
428
|
-
* incurring proxy access / tracking overhead or write without triggering
|
|
429
|
-
* changes. It is **not** recommended to hold a persistent reference to the
|
|
430
|
-
* original object. Use with caution.
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* ```js
|
|
434
|
-
* const foo = {}
|
|
435
|
-
* const reactiveFoo = reactive(foo)
|
|
436
|
-
*
|
|
437
|
-
* console.log(toRaw(reactiveFoo) === foo) // true
|
|
438
|
-
* ```
|
|
439
|
-
*
|
|
440
|
-
* @param observed - The object for which the "raw" value is requested.
|
|
441
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
|
|
442
|
-
*/
|
|
420
|
+
* Returns the raw, original object of a Vue-created proxy.
|
|
421
|
+
*
|
|
422
|
+
* `toRaw()` can return the original object from proxies created by
|
|
423
|
+
* {@link reactive}, {@link readonly}, {@link shallowReactive} or
|
|
424
|
+
* {@link shallowReadonly}.
|
|
425
|
+
*
|
|
426
|
+
* This is an escape hatch that can be used to temporarily read without
|
|
427
|
+
* incurring proxy access / tracking overhead or write without triggering
|
|
428
|
+
* changes. It is **not** recommended to hold a persistent reference to the
|
|
429
|
+
* original object. Use with caution.
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```js
|
|
433
|
+
* const foo = {}
|
|
434
|
+
* const reactiveFoo = reactive(foo)
|
|
435
|
+
*
|
|
436
|
+
* console.log(toRaw(reactiveFoo) === foo) // true
|
|
437
|
+
* ```
|
|
438
|
+
*
|
|
439
|
+
* @param observed - The object for which the "raw" value is requested.
|
|
440
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
|
|
441
|
+
*/
|
|
443
442
|
export declare function toRaw<T>(observed: T): T;
|
|
444
443
|
export type Raw<T> = T & {
|
|
445
444
|
[RawSymbol]?: true;
|
|
446
445
|
};
|
|
447
446
|
/**
|
|
448
|
-
* Marks an object so that it will never be converted to a proxy. Returns the
|
|
449
|
-
* object itself.
|
|
450
|
-
*
|
|
451
|
-
* @example
|
|
452
|
-
* ```js
|
|
453
|
-
* const foo = markRaw({})
|
|
454
|
-
* console.log(isReactive(reactive(foo))) // false
|
|
455
|
-
*
|
|
456
|
-
* // also works when nested inside other reactive objects
|
|
457
|
-
* const bar = reactive({ foo })
|
|
458
|
-
* console.log(isReactive(bar.foo)) // false
|
|
459
|
-
* ```
|
|
460
|
-
*
|
|
461
|
-
* **Warning:** `markRaw()` together with the shallow APIs such as
|
|
462
|
-
* {@link shallowReactive} allow you to selectively opt-out of the default
|
|
463
|
-
* deep reactive/readonly conversion and embed raw, non-proxied objects in your
|
|
464
|
-
* state graph.
|
|
465
|
-
*
|
|
466
|
-
* @param value - The object to be marked as "raw".
|
|
467
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
|
|
468
|
-
*/
|
|
447
|
+
* Marks an object so that it will never be converted to a proxy. Returns the
|
|
448
|
+
* object itself.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```js
|
|
452
|
+
* const foo = markRaw({})
|
|
453
|
+
* console.log(isReactive(reactive(foo))) // false
|
|
454
|
+
*
|
|
455
|
+
* // also works when nested inside other reactive objects
|
|
456
|
+
* const bar = reactive({ foo })
|
|
457
|
+
* console.log(isReactive(bar.foo)) // false
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* **Warning:** `markRaw()` together with the shallow APIs such as
|
|
461
|
+
* {@link shallowReactive} allow you to selectively opt-out of the default
|
|
462
|
+
* deep reactive/readonly conversion and embed raw, non-proxied objects in your
|
|
463
|
+
* state graph.
|
|
464
|
+
*
|
|
465
|
+
* @param value - The object to be marked as "raw".
|
|
466
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
|
|
467
|
+
*/
|
|
469
468
|
export declare function markRaw<T extends object>(value: T): Raw<T>;
|
|
470
469
|
/**
|
|
471
|
-
* Returns a reactive proxy of the given value (if possible).
|
|
472
|
-
*
|
|
473
|
-
* If the given value is not an object, the original value itself is returned.
|
|
474
|
-
*
|
|
475
|
-
* @param value - The value for which a reactive proxy shall be created.
|
|
476
|
-
*/
|
|
470
|
+
* Returns a reactive proxy of the given value (if possible).
|
|
471
|
+
*
|
|
472
|
+
* If the given value is not an object, the original value itself is returned.
|
|
473
|
+
*
|
|
474
|
+
* @param value - The value for which a reactive proxy shall be created.
|
|
475
|
+
*/
|
|
477
476
|
export declare const toReactive: <T extends unknown>(value: T) => T;
|
|
478
477
|
/**
|
|
479
|
-
* Returns a readonly proxy of the given value (if possible).
|
|
480
|
-
*
|
|
481
|
-
* If the given value is not an object, the original value itself is returned.
|
|
482
|
-
*
|
|
483
|
-
* @param value - The value for which a readonly proxy shall be created.
|
|
484
|
-
*/
|
|
478
|
+
* Returns a readonly proxy of the given value (if possible).
|
|
479
|
+
*
|
|
480
|
+
* If the given value is not an object, the original value itself is returned.
|
|
481
|
+
*
|
|
482
|
+
* @param value - The value for which a readonly proxy shall be created.
|
|
483
|
+
*/
|
|
485
484
|
export declare const toReadonly: <T extends unknown>(value: T) => DeepReadonly<T>;
|
|
486
485
|
//#endregion
|
|
487
486
|
//#region temp/packages/reactivity/src/ref.d.ts
|
|
@@ -491,26 +490,26 @@ export interface Ref<T = any, S = T> {
|
|
|
491
490
|
get value(): T;
|
|
492
491
|
set value(_: S);
|
|
493
492
|
/**
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
493
|
+
* Type differentiator only.
|
|
494
|
+
* We need this to be in public d.ts but don't want it to show up in IDE
|
|
495
|
+
* autocomplete, so we use a private Symbol instead.
|
|
496
|
+
*/
|
|
498
497
|
[RefSymbol]: true;
|
|
499
498
|
}
|
|
500
499
|
/**
|
|
501
|
-
* Checks if a value is a ref object.
|
|
502
|
-
*
|
|
503
|
-
* @param r - The value to inspect.
|
|
504
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isref}
|
|
505
|
-
*/
|
|
500
|
+
* Checks if a value is a ref object.
|
|
501
|
+
*
|
|
502
|
+
* @param r - The value to inspect.
|
|
503
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isref}
|
|
504
|
+
*/
|
|
506
505
|
export declare function isRef<T>(r: Ref<T> | unknown): r is Ref<T>;
|
|
507
506
|
/**
|
|
508
|
-
* Takes an inner value and returns a reactive and mutable ref object, which
|
|
509
|
-
* has a single property `.value` that points to the inner value.
|
|
510
|
-
*
|
|
511
|
-
* @param value - The object to wrap in the ref.
|
|
512
|
-
* @see {@link https://vuejs.org/api/reactivity-core.html#ref}
|
|
513
|
-
*/
|
|
507
|
+
* Takes an inner value and returns a reactive and mutable ref object, which
|
|
508
|
+
* has a single property `.value` that points to the inner value.
|
|
509
|
+
*
|
|
510
|
+
* @param value - The object to wrap in the ref.
|
|
511
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#ref}
|
|
512
|
+
*/
|
|
514
513
|
export declare function ref<T>(value: T): [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T>;
|
|
515
514
|
export declare function ref<T = any>(): Ref<T | undefined>;
|
|
516
515
|
declare const ShallowRefMarker: unique symbol;
|
|
@@ -518,223 +517,223 @@ export type ShallowRef<T = any, S = T> = Ref<T, S> & {
|
|
|
518
517
|
[ShallowRefMarker]?: true;
|
|
519
518
|
};
|
|
520
519
|
/**
|
|
521
|
-
* Shallow version of {@link ref}.
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* ```js
|
|
525
|
-
* const state = shallowRef({ count: 1 })
|
|
526
|
-
*
|
|
527
|
-
* // does NOT trigger change
|
|
528
|
-
* state.value.count = 2
|
|
529
|
-
*
|
|
530
|
-
* // does trigger change
|
|
531
|
-
* state.value = { count: 2 }
|
|
532
|
-
* ```
|
|
533
|
-
*
|
|
534
|
-
* @param value - The "inner value" for the shallow ref.
|
|
535
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowref}
|
|
536
|
-
*/
|
|
520
|
+
* Shallow version of {@link ref}.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```js
|
|
524
|
+
* const state = shallowRef({ count: 1 })
|
|
525
|
+
*
|
|
526
|
+
* // does NOT trigger change
|
|
527
|
+
* state.value.count = 2
|
|
528
|
+
*
|
|
529
|
+
* // does trigger change
|
|
530
|
+
* state.value = { count: 2 }
|
|
531
|
+
* ```
|
|
532
|
+
*
|
|
533
|
+
* @param value - The "inner value" for the shallow ref.
|
|
534
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowref}
|
|
535
|
+
*/
|
|
537
536
|
export declare function shallowRef<T>(value: T): Ref extends T ? T extends Ref ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T> : ShallowRef<T>;
|
|
538
537
|
export declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
|
|
539
538
|
/**
|
|
540
|
-
* Force trigger effects that depends on a shallow ref. This is typically used
|
|
541
|
-
* after making deep mutations to the inner value of a shallow ref.
|
|
542
|
-
*
|
|
543
|
-
* @example
|
|
544
|
-
* ```js
|
|
545
|
-
* const shallow = shallowRef({
|
|
546
|
-
* greet: 'Hello, world'
|
|
547
|
-
* })
|
|
548
|
-
*
|
|
549
|
-
* // Logs "Hello, world" once for the first run-through
|
|
550
|
-
* watchEffect(() => {
|
|
551
|
-
* console.log(shallow.value.greet)
|
|
552
|
-
* })
|
|
553
|
-
*
|
|
554
|
-
* // This won't trigger the effect because the ref is shallow
|
|
555
|
-
* shallow.value.greet = 'Hello, universe'
|
|
556
|
-
*
|
|
557
|
-
* // Logs "Hello, universe"
|
|
558
|
-
* triggerRef(shallow)
|
|
559
|
-
* ```
|
|
560
|
-
*
|
|
561
|
-
* @param ref - The ref whose tied effects shall be executed.
|
|
562
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
|
|
563
|
-
*/
|
|
539
|
+
* Force trigger effects that depends on a shallow ref. This is typically used
|
|
540
|
+
* after making deep mutations to the inner value of a shallow ref.
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```js
|
|
544
|
+
* const shallow = shallowRef({
|
|
545
|
+
* greet: 'Hello, world'
|
|
546
|
+
* })
|
|
547
|
+
*
|
|
548
|
+
* // Logs "Hello, world" once for the first run-through
|
|
549
|
+
* watchEffect(() => {
|
|
550
|
+
* console.log(shallow.value.greet)
|
|
551
|
+
* })
|
|
552
|
+
*
|
|
553
|
+
* // This won't trigger the effect because the ref is shallow
|
|
554
|
+
* shallow.value.greet = 'Hello, universe'
|
|
555
|
+
*
|
|
556
|
+
* // Logs "Hello, universe"
|
|
557
|
+
* triggerRef(shallow)
|
|
558
|
+
* ```
|
|
559
|
+
*
|
|
560
|
+
* @param ref - The ref whose tied effects shall be executed.
|
|
561
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
|
|
562
|
+
*/
|
|
564
563
|
export declare function triggerRef(ref: Ref): void;
|
|
565
564
|
export type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>;
|
|
566
565
|
export type MaybeRefOrGetter<T = any> = MaybeRef<T> | ComputedRef<T> | (() => T);
|
|
567
566
|
/**
|
|
568
|
-
* Returns the inner value if the argument is a ref, otherwise return the
|
|
569
|
-
* argument itself. This is a sugar function for
|
|
570
|
-
* `val = isRef(val) ? val.value : val`.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```js
|
|
574
|
-
* function useFoo(x: number | Ref<number>) {
|
|
575
|
-
* const unwrapped = unref(x)
|
|
576
|
-
* // unwrapped is guaranteed to be number now
|
|
577
|
-
* }
|
|
578
|
-
* ```
|
|
579
|
-
*
|
|
580
|
-
* @param ref - Ref or plain value to be converted into the plain value.
|
|
581
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
|
|
582
|
-
*/
|
|
567
|
+
* Returns the inner value if the argument is a ref, otherwise return the
|
|
568
|
+
* argument itself. This is a sugar function for
|
|
569
|
+
* `val = isRef(val) ? val.value : val`.
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```js
|
|
573
|
+
* function useFoo(x: number | Ref<number>) {
|
|
574
|
+
* const unwrapped = unref(x)
|
|
575
|
+
* // unwrapped is guaranteed to be number now
|
|
576
|
+
* }
|
|
577
|
+
* ```
|
|
578
|
+
*
|
|
579
|
+
* @param ref - Ref or plain value to be converted into the plain value.
|
|
580
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
|
|
581
|
+
*/
|
|
583
582
|
export declare function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T;
|
|
584
583
|
/**
|
|
585
|
-
* Normalizes values / refs / getters to values.
|
|
586
|
-
* This is similar to {@link unref}, except that it also normalizes getters.
|
|
587
|
-
* If the argument is a getter, it will be invoked and its return value will
|
|
588
|
-
* be returned.
|
|
589
|
-
*
|
|
590
|
-
* @example
|
|
591
|
-
* ```js
|
|
592
|
-
* toValue(1) // 1
|
|
593
|
-
* toValue(ref(1)) // 1
|
|
594
|
-
* toValue(() => 1) // 1
|
|
595
|
-
* ```
|
|
596
|
-
*
|
|
597
|
-
* @param source - A getter, an existing ref, or a non-function value.
|
|
598
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
|
|
599
|
-
*/
|
|
584
|
+
* Normalizes values / refs / getters to values.
|
|
585
|
+
* This is similar to {@link unref}, except that it also normalizes getters.
|
|
586
|
+
* If the argument is a getter, it will be invoked and its return value will
|
|
587
|
+
* be returned.
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* ```js
|
|
591
|
+
* toValue(1) // 1
|
|
592
|
+
* toValue(ref(1)) // 1
|
|
593
|
+
* toValue(() => 1) // 1
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* @param source - A getter, an existing ref, or a non-function value.
|
|
597
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
|
|
598
|
+
*/
|
|
600
599
|
export declare function toValue<T>(source: MaybeRefOrGetter<T>): T;
|
|
601
600
|
/**
|
|
602
|
-
* Returns a proxy for the given object that shallowly unwraps properties that
|
|
603
|
-
* are refs. If the object already is reactive, it's returned as-is. If not, a
|
|
604
|
-
* new reactive proxy is created.
|
|
605
|
-
*
|
|
606
|
-
* @param objectWithRefs - Either an already-reactive object or a simple object
|
|
607
|
-
* that contains refs.
|
|
608
|
-
*/
|
|
601
|
+
* Returns a proxy for the given object that shallowly unwraps properties that
|
|
602
|
+
* are refs. If the object already is reactive, it's returned as-is. If not, a
|
|
603
|
+
* new reactive proxy is created.
|
|
604
|
+
*
|
|
605
|
+
* @param objectWithRefs - Either an already-reactive object or a simple object
|
|
606
|
+
* that contains refs.
|
|
607
|
+
*/
|
|
609
608
|
export declare function proxyRefs<T extends object>(objectWithRefs: T): ShallowUnwrapRef<T>;
|
|
610
609
|
export type CustomRefFactory<T, S = T> = (track: () => void, trigger: () => void) => {
|
|
611
610
|
get: () => T;
|
|
612
611
|
set: (value: S) => void;
|
|
613
612
|
};
|
|
614
613
|
/**
|
|
615
|
-
* Creates a customized ref with explicit control over its dependency tracking
|
|
616
|
-
* and updates triggering.
|
|
617
|
-
*
|
|
618
|
-
* @param factory - The function that receives the `track` and `trigger` callbacks.
|
|
619
|
-
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref}
|
|
620
|
-
*/
|
|
614
|
+
* Creates a customized ref with explicit control over its dependency tracking
|
|
615
|
+
* and updates triggering.
|
|
616
|
+
*
|
|
617
|
+
* @param factory - The function that receives the `track` and `trigger` callbacks.
|
|
618
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref}
|
|
619
|
+
*/
|
|
621
620
|
export declare function customRef<T, S = T>(factory: CustomRefFactory<T, S>): Ref<T, S>;
|
|
622
|
-
export type ToRefs<T = any> = { [K in keyof T]: ToRef<T[K]
|
|
621
|
+
export type ToRefs<T = any> = { [K in keyof T]: ToRef<T[K]>; };
|
|
623
622
|
type ArrayStringKey<T> = T extends readonly any[] ? number extends T["length"] ? `${number}` : never : never;
|
|
624
623
|
type ToRefKey<T> = keyof T | ArrayStringKey<T>;
|
|
625
624
|
type ToRefValue<T extends object, K extends ToRefKey<T>> = K extends keyof T ? T[K] : T extends readonly (infer V)[] ? K extends ArrayStringKey<T> ? V : never : never;
|
|
626
625
|
/**
|
|
627
|
-
* Converts a reactive object to a plain object where each property of the
|
|
628
|
-
* resulting object is a ref pointing to the corresponding property of the
|
|
629
|
-
* original object. Each individual ref is created using {@link toRef}.
|
|
630
|
-
*
|
|
631
|
-
* @param object - Reactive object to be made into an object of linked refs.
|
|
632
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
|
|
633
|
-
*/
|
|
626
|
+
* Converts a reactive object to a plain object where each property of the
|
|
627
|
+
* resulting object is a ref pointing to the corresponding property of the
|
|
628
|
+
* original object. Each individual ref is created using {@link toRef}.
|
|
629
|
+
*
|
|
630
|
+
* @param object - Reactive object to be made into an object of linked refs.
|
|
631
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
|
|
632
|
+
*/
|
|
634
633
|
export declare function toRefs<T extends object>(object: T): ToRefs<T>;
|
|
635
634
|
export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>;
|
|
636
635
|
/**
|
|
637
|
-
* Used to normalize values / refs / getters into refs.
|
|
638
|
-
*
|
|
639
|
-
* @example
|
|
640
|
-
* ```js
|
|
641
|
-
* // returns existing refs as-is
|
|
642
|
-
* toRef(existingRef)
|
|
643
|
-
*
|
|
644
|
-
* // creates a ref that calls the getter on .value access
|
|
645
|
-
* toRef(() => props.foo)
|
|
646
|
-
*
|
|
647
|
-
* // creates normal refs from non-function values
|
|
648
|
-
* // equivalent to ref(1)
|
|
649
|
-
* toRef(1)
|
|
650
|
-
* ```
|
|
651
|
-
*
|
|
652
|
-
* Can also be used to create a ref for a property on a source reactive object.
|
|
653
|
-
* The created ref is synced with its source property: mutating the source
|
|
654
|
-
* property will update the ref, and vice-versa.
|
|
655
|
-
*
|
|
656
|
-
* @example
|
|
657
|
-
* ```js
|
|
658
|
-
* const state = reactive({
|
|
659
|
-
* foo: 1,
|
|
660
|
-
* bar: 2
|
|
661
|
-
* })
|
|
662
|
-
*
|
|
663
|
-
* const fooRef = toRef(state, 'foo')
|
|
664
|
-
*
|
|
665
|
-
* // mutating the ref updates the original
|
|
666
|
-
* fooRef.value++
|
|
667
|
-
* console.log(state.foo) // 2
|
|
668
|
-
*
|
|
669
|
-
* // mutating the original also updates the ref
|
|
670
|
-
* state.foo++
|
|
671
|
-
* console.log(fooRef.value) // 3
|
|
672
|
-
* ```
|
|
673
|
-
*
|
|
674
|
-
* @param source - A getter, an existing ref, a non-function value, or a
|
|
675
|
-
* reactive object to create a property ref from.
|
|
676
|
-
* @param [key] - (optional) Name of the property in the reactive object.
|
|
677
|
-
* @see {@link https://vuejs.org/api/reactivity-utilities.html#toref}
|
|
678
|
-
*/
|
|
636
|
+
* Used to normalize values / refs / getters into refs.
|
|
637
|
+
*
|
|
638
|
+
* @example
|
|
639
|
+
* ```js
|
|
640
|
+
* // returns existing refs as-is
|
|
641
|
+
* toRef(existingRef)
|
|
642
|
+
*
|
|
643
|
+
* // creates a ref that calls the getter on .value access
|
|
644
|
+
* toRef(() => props.foo)
|
|
645
|
+
*
|
|
646
|
+
* // creates normal refs from non-function values
|
|
647
|
+
* // equivalent to ref(1)
|
|
648
|
+
* toRef(1)
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* Can also be used to create a ref for a property on a source reactive object.
|
|
652
|
+
* The created ref is synced with its source property: mutating the source
|
|
653
|
+
* property will update the ref, and vice-versa.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```js
|
|
657
|
+
* const state = reactive({
|
|
658
|
+
* foo: 1,
|
|
659
|
+
* bar: 2
|
|
660
|
+
* })
|
|
661
|
+
*
|
|
662
|
+
* const fooRef = toRef(state, 'foo')
|
|
663
|
+
*
|
|
664
|
+
* // mutating the ref updates the original
|
|
665
|
+
* fooRef.value++
|
|
666
|
+
* console.log(state.foo) // 2
|
|
667
|
+
*
|
|
668
|
+
* // mutating the original also updates the ref
|
|
669
|
+
* state.foo++
|
|
670
|
+
* console.log(fooRef.value) // 3
|
|
671
|
+
* ```
|
|
672
|
+
*
|
|
673
|
+
* @param source - A getter, an existing ref, a non-function value, or a
|
|
674
|
+
* reactive object to create a property ref from.
|
|
675
|
+
* @param [key] - (optional) Name of the property in the reactive object.
|
|
676
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#toref}
|
|
677
|
+
*/
|
|
679
678
|
export declare function toRef<T>(value: T): T extends (() => infer R) ? Readonly<Ref<R>> : T extends Ref ? T : Ref<UnwrapRef<T>>;
|
|
680
679
|
export declare function toRef<T extends object, K extends ToRefKey<T>>(object: T, key: K): ToRef<ToRefValue<T, K>>;
|
|
681
680
|
export declare function toRef<T extends object, K extends ToRefKey<T>>(object: T, key: K, defaultValue: ToRefValue<T, K>): ToRef<Exclude<ToRefValue<T, K>, undefined>>;
|
|
682
681
|
/**
|
|
683
|
-
* This is a special exported interface for other packages to declare
|
|
684
|
-
* additional types that should bail out for ref unwrapping. For example
|
|
685
|
-
* \@vue/runtime-dom can declare it like so in its d.ts:
|
|
686
|
-
*
|
|
687
|
-
* ``` ts
|
|
688
|
-
* declare module '@vue/reactivity' {
|
|
689
|
-
* export interface RefUnwrapBailTypes {
|
|
690
|
-
* runtimeDOMBailTypes: Node | Window
|
|
691
|
-
* }
|
|
692
|
-
* }
|
|
693
|
-
* ```
|
|
694
|
-
*/
|
|
682
|
+
* This is a special exported interface for other packages to declare
|
|
683
|
+
* additional types that should bail out for ref unwrapping. For example
|
|
684
|
+
* \@vue/runtime-dom can declare it like so in its d.ts:
|
|
685
|
+
*
|
|
686
|
+
* ``` ts
|
|
687
|
+
* declare module '@vue/reactivity' {
|
|
688
|
+
* export interface RefUnwrapBailTypes {
|
|
689
|
+
* runtimeDOMBailTypes: Node | Window
|
|
690
|
+
* }
|
|
691
|
+
* }
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
695
694
|
export interface RefUnwrapBailTypes {}
|
|
696
|
-
export type ShallowUnwrapRef<T> = T extends ShallowReactiveBrand ? T : { [K in keyof T]: DistributeRef<T[K]
|
|
695
|
+
export type ShallowUnwrapRef<T> = T extends ShallowReactiveBrand ? T : { [K in keyof T]: DistributeRef<T[K]>; };
|
|
697
696
|
type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T;
|
|
698
697
|
export type UnwrapRef<T> = T extends ShallowRef<infer V, unknown> ? V : T extends Ref<infer V, unknown> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
|
|
699
698
|
type UnwrapRefSimple<T> = T extends Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
|
|
700
699
|
[RawSymbol]?: true;
|
|
701
|
-
} ? T : T extends ShallowReactiveBrand ? T : T extends Map<infer K, infer V> ? Map<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof Map<any, any>>> : T extends WeakMap<infer K, infer V> ? WeakMap<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof WeakMap<any, any>>> : T extends Set<infer V> ? Set<UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof Set<any>>> : T extends WeakSet<infer V> ? WeakSet<UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof WeakSet<any>>> : T extends ReadonlyArray<any> ? { [K in keyof T]: UnwrapRefSimple<T[K]
|
|
700
|
+
} ? T : T extends ShallowReactiveBrand ? T : T extends Map<infer K, infer V> ? Map<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof Map<any, any>>> : T extends WeakMap<infer K, infer V> ? WeakMap<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof WeakMap<any, any>>> : T extends Set<infer V> ? Set<UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof Set<any>>> : T extends WeakSet<infer V> ? WeakSet<UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof WeakSet<any>>> : T extends ReadonlyArray<any> ? { [K in keyof T]: UnwrapRefSimple<T[K]>; } : T extends object ? { [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>; } : T;
|
|
702
701
|
//#endregion
|
|
703
702
|
//#region temp/packages/reactivity/src/dep.d.ts
|
|
704
703
|
export declare const ITERATE_KEY: unique symbol;
|
|
705
704
|
export declare const MAP_KEY_ITERATE_KEY: unique symbol;
|
|
706
705
|
export declare const ARRAY_ITERATE_KEY: unique symbol;
|
|
707
706
|
/**
|
|
708
|
-
* Tracks access to a reactive property.
|
|
709
|
-
*
|
|
710
|
-
* This will check which effect is running at the moment and record it as dep
|
|
711
|
-
* which records all effects that depend on the reactive property.
|
|
712
|
-
*
|
|
713
|
-
* @param target - Object holding the reactive property.
|
|
714
|
-
* @param type - Defines the type of access to the reactive property.
|
|
715
|
-
* @param key - Identifier of the reactive property to track.
|
|
716
|
-
*/
|
|
707
|
+
* Tracks access to a reactive property.
|
|
708
|
+
*
|
|
709
|
+
* This will check which effect is running at the moment and record it as dep
|
|
710
|
+
* which records all effects that depend on the reactive property.
|
|
711
|
+
*
|
|
712
|
+
* @param target - Object holding the reactive property.
|
|
713
|
+
* @param type - Defines the type of access to the reactive property.
|
|
714
|
+
* @param key - Identifier of the reactive property to track.
|
|
715
|
+
*/
|
|
717
716
|
export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
|
|
718
717
|
/**
|
|
719
|
-
* Finds all deps associated with the target (or a specific property) and
|
|
720
|
-
* triggers the effects stored within.
|
|
721
|
-
*
|
|
722
|
-
* @param target - The reactive object.
|
|
723
|
-
* @param type - Defines the type of the operation that needs to trigger effects.
|
|
724
|
-
* @param key - Can be used to target a specific reactive property in the target object.
|
|
725
|
-
*/
|
|
718
|
+
* Finds all deps associated with the target (or a specific property) and
|
|
719
|
+
* triggers the effects stored within.
|
|
720
|
+
*
|
|
721
|
+
* @param target - The reactive object.
|
|
722
|
+
* @param type - Defines the type of the operation that needs to trigger effects.
|
|
723
|
+
* @param key - Can be used to target a specific reactive property in the target object.
|
|
724
|
+
*/
|
|
726
725
|
export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
|
|
727
726
|
//#endregion
|
|
728
727
|
//#region temp/packages/reactivity/src/arrayInstrumentations.d.ts
|
|
729
728
|
/**
|
|
730
|
-
* Track array iteration and return:
|
|
731
|
-
* - if input is reactive: a cloned raw array with reactive values
|
|
732
|
-
* - if input is non-reactive or shallowReactive: the original raw array
|
|
733
|
-
*/
|
|
729
|
+
* Track array iteration and return:
|
|
730
|
+
* - if input is reactive: a cloned raw array with reactive values
|
|
731
|
+
* - if input is non-reactive or shallowReactive: the original raw array
|
|
732
|
+
*/
|
|
734
733
|
export declare function reactiveReadArray<T>(array: T[]): T[];
|
|
735
734
|
/**
|
|
736
|
-
* Track array iteration and return raw array
|
|
737
|
-
*/
|
|
735
|
+
* Track array iteration and return raw array
|
|
736
|
+
*/
|
|
738
737
|
export declare function shallowReadArray<T>(arr: T[]): T[];
|
|
739
738
|
//#endregion
|
|
740
739
|
//#region temp/packages/reactivity/src/watch.d.ts
|
|
@@ -760,20 +759,20 @@ export interface WatchHandle extends WatchStopHandle {
|
|
|
760
759
|
stop: () => void;
|
|
761
760
|
}
|
|
762
761
|
/**
|
|
763
|
-
* Returns the current active effect if there is one.
|
|
764
|
-
*/
|
|
762
|
+
* Returns the current active effect if there is one.
|
|
763
|
+
*/
|
|
765
764
|
export declare function getCurrentWatcher(): ReactiveEffect<any> | undefined;
|
|
766
765
|
/**
|
|
767
|
-
* Registers a cleanup callback on the current active effect. This
|
|
768
|
-
* registered cleanup callback will be invoked right before the
|
|
769
|
-
* associated effect re-runs.
|
|
770
|
-
*
|
|
771
|
-
* @param cleanupFn - The callback function to attach to the effect's cleanup.
|
|
772
|
-
* @param failSilently - if `true`, will not throw warning when called without
|
|
773
|
-
* an active effect.
|
|
774
|
-
* @param owner - The effect that this cleanup function should be attached to.
|
|
775
|
-
* By default, the current active effect.
|
|
776
|
-
*/
|
|
766
|
+
* Registers a cleanup callback on the current active effect. This
|
|
767
|
+
* registered cleanup callback will be invoked right before the
|
|
768
|
+
* associated effect re-runs.
|
|
769
|
+
*
|
|
770
|
+
* @param cleanupFn - The callback function to attach to the effect's cleanup.
|
|
771
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
772
|
+
* an active effect.
|
|
773
|
+
* @param owner - The effect that this cleanup function should be attached to.
|
|
774
|
+
* By default, the current active effect.
|
|
775
|
+
*/
|
|
777
776
|
export declare function onWatcherCleanup(cleanupFn: () => void, failSilently?: boolean, owner?: WatcherEffect | undefined): void;
|
|
778
777
|
export declare class WatcherEffect extends ReactiveEffect {
|
|
779
778
|
cb?: WatchCallback<any, any> | null | undefined;
|