@vue/reactivity 3.6.0-beta.9 → 3.6.0-rc.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.
- package/dist/reactivity.cjs.js +164 -110
- package/dist/reactivity.cjs.prod.js +147 -108
- package/dist/reactivity.d.ts +477 -477
- package/dist/reactivity.esm-browser.js +155 -120
- package/dist/reactivity.esm-browser.prod.js +2 -2
- package/dist/reactivity.esm-bundler.js +154 -111
- package/dist/reactivity.global.js +165 -119
- 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,225 +261,226 @@ 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
|
-
declare
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* state
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* @
|
|
313
|
-
|
|
279
|
+
declare class ShallowReactiveBrandClass {
|
|
280
|
+
private __shallowReactiveBrand?;
|
|
281
|
+
}
|
|
282
|
+
type ShallowReactiveBrand = ShallowReactiveBrandClass;
|
|
283
|
+
export type ShallowReactive<T> = T & ShallowReactiveBrand;
|
|
284
|
+
/**
|
|
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
|
+
*/
|
|
314
314
|
export declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
|
|
315
315
|
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
316
316
|
type Builtin = Primitive | Function | Date | Error | RegExp;
|
|
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]
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
347
347
|
export declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>>;
|
|
348
348
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
378
378
|
export declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
|
|
379
379
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
397
397
|
export declare function isReactive(value: unknown): boolean;
|
|
398
398
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
409
409
|
export declare function isReadonly(value: unknown): boolean;
|
|
410
410
|
export declare function isShallow(value: unknown): boolean;
|
|
411
411
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
418
418
|
export declare function isProxy(value: any): boolean;
|
|
419
419
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
442
442
|
export declare function toRaw<T>(observed: T): T;
|
|
443
443
|
export type Raw<T> = T & {
|
|
444
444
|
[RawSymbol]?: true;
|
|
445
445
|
};
|
|
446
446
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
468
468
|
export declare function markRaw<T extends object>(value: T): Raw<T>;
|
|
469
469
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
476
476
|
export declare const toReactive: <T extends unknown>(value: T) => T;
|
|
477
477
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
484
484
|
export declare const toReadonly: <T extends unknown>(value: T) => DeepReadonly<T>;
|
|
485
485
|
//#endregion
|
|
486
486
|
//#region temp/packages/reactivity/src/ref.d.ts
|
|
@@ -490,26 +490,26 @@ export interface Ref<T = any, S = T> {
|
|
|
490
490
|
get value(): T;
|
|
491
491
|
set value(_: S);
|
|
492
492
|
/**
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
+
*/
|
|
497
497
|
[RefSymbol]: true;
|
|
498
498
|
}
|
|
499
499
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
505
505
|
export declare function isRef<T>(r: Ref<T> | unknown): r is Ref<T>;
|
|
506
506
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
513
513
|
export declare function ref<T>(value: T): [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T>;
|
|
514
514
|
export declare function ref<T = any>(): Ref<T | undefined>;
|
|
515
515
|
declare const ShallowRefMarker: unique symbol;
|
|
@@ -517,225 +517,225 @@ export type ShallowRef<T = any, S = T> = Ref<T, S> & {
|
|
|
517
517
|
[ShallowRefMarker]?: true;
|
|
518
518
|
};
|
|
519
519
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
536
536
|
export declare function shallowRef<T>(value: T): Ref extends T ? T extends Ref ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T> : ShallowRef<T>;
|
|
537
537
|
export declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
|
|
538
538
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
563
563
|
export declare function triggerRef(ref: Ref): void;
|
|
564
564
|
export type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>;
|
|
565
565
|
export type MaybeRefOrGetter<T = any> = MaybeRef<T> | ComputedRef<T> | (() => T);
|
|
566
566
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
582
582
|
export declare function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T;
|
|
583
583
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
599
599
|
export declare function toValue<T>(source: MaybeRefOrGetter<T>): T;
|
|
600
600
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
608
608
|
export declare function proxyRefs<T extends object>(objectWithRefs: T): ShallowUnwrapRef<T>;
|
|
609
|
-
export type CustomRefFactory<T> = (track: () => void, trigger: () => void) => {
|
|
609
|
+
export type CustomRefFactory<T, S = T> = (track: () => void, trigger: () => void) => {
|
|
610
610
|
get: () => T;
|
|
611
|
-
set: (value:
|
|
611
|
+
set: (value: S) => void;
|
|
612
612
|
};
|
|
613
613
|
/**
|
|
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
|
-
*/
|
|
620
|
-
export declare function customRef<T>(factory: CustomRefFactory<T>): Ref<T>;
|
|
621
|
-
export type ToRefs<T = any> = { [K in keyof T]: ToRef<T[K]
|
|
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
|
+
*/
|
|
620
|
+
export declare function customRef<T, S = T>(factory: CustomRefFactory<T, S>): Ref<T, S>;
|
|
621
|
+
export type ToRefs<T = any> = { [K in keyof T]: ToRef<T[K]>; };
|
|
622
622
|
type ArrayStringKey<T> = T extends readonly any[] ? number extends T["length"] ? `${number}` : never : never;
|
|
623
623
|
type ToRefKey<T> = keyof T | ArrayStringKey<T>;
|
|
624
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;
|
|
625
625
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
633
633
|
export declare function toRefs<T extends object>(object: T): ToRefs<T>;
|
|
634
634
|
export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>;
|
|
635
635
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
678
678
|
export declare function toRef<T>(value: T): T extends (() => infer R) ? Readonly<Ref<R>> : T extends Ref ? T : Ref<UnwrapRef<T>>;
|
|
679
679
|
export declare function toRef<T extends object, K extends ToRefKey<T>>(object: T, key: K): ToRef<ToRefValue<T, K>>;
|
|
680
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>>;
|
|
681
681
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
694
694
|
export interface RefUnwrapBailTypes {}
|
|
695
|
-
export type ShallowUnwrapRef<T> = { [K in keyof T]: DistributeRef<T[K]
|
|
695
|
+
export type ShallowUnwrapRef<T> = T extends ShallowReactiveBrand ? T : { [K in keyof T]: DistributeRef<T[K]>; };
|
|
696
696
|
type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T;
|
|
697
697
|
export type UnwrapRef<T> = T extends ShallowRef<infer V, unknown> ? V : T extends Ref<infer V, unknown> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
|
|
698
698
|
type UnwrapRefSimple<T> = T extends Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
|
|
699
699
|
[RawSymbol]?: true;
|
|
700
|
-
} ? 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]
|
|
701
|
-
[ShallowReactiveMarker]: never;
|
|
702
|
-
} ? T : T extends object ? { [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]> } : T;
|
|
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;
|
|
703
701
|
//#endregion
|
|
704
702
|
//#region temp/packages/reactivity/src/dep.d.ts
|
|
705
703
|
export declare const ITERATE_KEY: unique symbol;
|
|
706
704
|
export declare const MAP_KEY_ITERATE_KEY: unique symbol;
|
|
707
705
|
export declare const ARRAY_ITERATE_KEY: unique symbol;
|
|
708
706
|
/**
|
|
709
|
-
* Tracks access to a reactive property.
|
|
710
|
-
*
|
|
711
|
-
* This will check which effect is running at the moment and record it as dep
|
|
712
|
-
* which records all effects that depend on the reactive property.
|
|
713
|
-
*
|
|
714
|
-
* @param target - Object holding the reactive property.
|
|
715
|
-
* @param type - Defines the type of access to the reactive property.
|
|
716
|
-
* @param key - Identifier of the reactive property to track.
|
|
717
|
-
*/
|
|
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
|
+
*/
|
|
718
716
|
export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
|
|
719
717
|
/**
|
|
720
|
-
* Finds all deps associated with the target (or a specific property) and
|
|
721
|
-
* triggers the effects stored within.
|
|
722
|
-
*
|
|
723
|
-
* @param target - The reactive object.
|
|
724
|
-
* @param type - Defines the type of the operation that needs to trigger effects.
|
|
725
|
-
* @param key - Can be used to target a specific reactive property in the target object.
|
|
726
|
-
*/
|
|
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
|
+
*/
|
|
727
725
|
export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
|
|
728
726
|
//#endregion
|
|
729
727
|
//#region temp/packages/reactivity/src/arrayInstrumentations.d.ts
|
|
730
728
|
/**
|
|
731
|
-
* Track array iteration and return:
|
|
732
|
-
* - if input is reactive: a cloned raw array with reactive values
|
|
733
|
-
* - if input is
|
|
734
|
-
|
|
729
|
+
* Track array iteration and return:
|
|
730
|
+
* - if input is reactive: a cloned raw array with reactive values
|
|
731
|
+
* - if input is readonly: a cloned raw array with readonly values, preserving
|
|
732
|
+
* reactivity
|
|
733
|
+
* - if input is raw or shallow: the original raw array
|
|
734
|
+
*/
|
|
735
735
|
export declare function reactiveReadArray<T>(array: T[]): T[];
|
|
736
736
|
/**
|
|
737
|
-
* Track array iteration and return raw array
|
|
738
|
-
*/
|
|
737
|
+
* Track array iteration and return raw array
|
|
738
|
+
*/
|
|
739
739
|
export declare function shallowReadArray<T>(arr: T[]): T[];
|
|
740
740
|
//#endregion
|
|
741
741
|
//#region temp/packages/reactivity/src/watch.d.ts
|
|
@@ -761,20 +761,20 @@ export interface WatchHandle extends WatchStopHandle {
|
|
|
761
761
|
stop: () => void;
|
|
762
762
|
}
|
|
763
763
|
/**
|
|
764
|
-
* Returns the current active effect if there is one.
|
|
765
|
-
*/
|
|
764
|
+
* Returns the current active effect if there is one.
|
|
765
|
+
*/
|
|
766
766
|
export declare function getCurrentWatcher(): ReactiveEffect<any> | undefined;
|
|
767
767
|
/**
|
|
768
|
-
* Registers a cleanup callback on the current active effect. This
|
|
769
|
-
* registered cleanup callback will be invoked right before the
|
|
770
|
-
* associated effect re-runs.
|
|
771
|
-
*
|
|
772
|
-
* @param cleanupFn - The callback function to attach to the effect's cleanup.
|
|
773
|
-
* @param failSilently - if `true`, will not throw warning when called without
|
|
774
|
-
* an active effect.
|
|
775
|
-
* @param owner - The effect that this cleanup function should be attached to.
|
|
776
|
-
* By default, the current active effect.
|
|
777
|
-
*/
|
|
768
|
+
* Registers a cleanup callback on the current active effect. This
|
|
769
|
+
* registered cleanup callback will be invoked right before the
|
|
770
|
+
* associated effect re-runs.
|
|
771
|
+
*
|
|
772
|
+
* @param cleanupFn - The callback function to attach to the effect's cleanup.
|
|
773
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
774
|
+
* an active effect.
|
|
775
|
+
* @param owner - The effect that this cleanup function should be attached to.
|
|
776
|
+
* By default, the current active effect.
|
|
777
|
+
*/
|
|
778
778
|
export declare function onWatcherCleanup(cleanupFn: () => void, failSilently?: boolean, owner?: WatcherEffect | undefined): void;
|
|
779
779
|
export declare class WatcherEffect extends ReactiveEffect {
|
|
780
780
|
cb?: WatchCallback<any, any> | null | undefined;
|