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