@zeus-js/signal 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/signal.cjs.js +1725 -0
- package/dist/signal.cjs.prod.js +1653 -0
- package/dist/signal.d.ts +914 -0
- package/dist/signal.esm-browser.js +1737 -0
- package/dist/signal.esm-browser.prod.js +1 -0
- package/dist/signal.esm-bundler.js +1684 -0
- package/dist/signal.global.js +1778 -0
- package/dist/signal.global.prod.js +1 -0
- package/index.js +7 -0
- package/package.json +56 -0
package/dist/signal.d.ts
ADDED
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
export interface ValueState<T = unknown> {
|
|
2
|
+
get value(): T;
|
|
3
|
+
set value(value: T);
|
|
4
|
+
}
|
|
5
|
+
type ProxyableInput = Record<PropertyKey, any> | readonly any[] | Map<unknown, unknown> | Set<unknown> | WeakMap<object, unknown> | WeakSet<object>;
|
|
6
|
+
export type State<T> = T extends ValueStateInput ? ValueState<T> : T extends ProxyableInput ? Reactive$1<T> : ValueState<T>;
|
|
7
|
+
type ValueStateInput = null | undefined | Date | RegExp | Error | Promise<any> | Function | Node;
|
|
8
|
+
type Reactive$1<T extends object> = T;
|
|
9
|
+
export declare function state<T extends ValueStateInput>(value: T): ValueState<T>;
|
|
10
|
+
export declare function state<T extends ProxyableInput>(value: T): Reactive$1<T>;
|
|
11
|
+
export declare function state<T>(value: T): ValueState<T>;
|
|
12
|
+
export declare function state<T = undefined>(): ValueState<T | undefined>;
|
|
13
|
+
export declare function isValueState<T = unknown>(value: unknown): value is ValueState<T>;
|
|
14
|
+
|
|
15
|
+
export declare enum TrackOpTypes {
|
|
16
|
+
GET = "get",
|
|
17
|
+
HAS = "has",
|
|
18
|
+
ITERATE = "iterate"
|
|
19
|
+
}
|
|
20
|
+
export declare enum TriggerOpTypes {
|
|
21
|
+
SET = "set",
|
|
22
|
+
ADD = "add",
|
|
23
|
+
DELETE = "delete",
|
|
24
|
+
CLEAR = "clear"
|
|
25
|
+
}
|
|
26
|
+
export declare enum ReactiveFlags {
|
|
27
|
+
SKIP = "__v_skip",
|
|
28
|
+
IS_REACTIVE = "__v_isReactive",
|
|
29
|
+
IS_READONLY = "__v_isReadonly",
|
|
30
|
+
IS_SHALLOW = "__v_isShallow",
|
|
31
|
+
RAW = "__v_raw",
|
|
32
|
+
IS_REF = "__v_isRef"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
import type { TrackOpTypes, TriggerOpTypes } from './constants';
|
|
36
|
+
export type EffectScheduler = (...args: any[]) => any;
|
|
37
|
+
export type DebuggerEvent = {
|
|
38
|
+
effect: Subscriber;
|
|
39
|
+
} & DebuggerEventExtraInfo;
|
|
40
|
+
export type DebuggerEventExtraInfo = {
|
|
41
|
+
target: object;
|
|
42
|
+
type: TrackOpTypes | TriggerOpTypes;
|
|
43
|
+
key: any;
|
|
44
|
+
newValue?: any;
|
|
45
|
+
oldValue?: any;
|
|
46
|
+
oldTarget?: Map<any, any> | Set<any>;
|
|
47
|
+
};
|
|
48
|
+
export interface DebuggerOptions {
|
|
49
|
+
onTrack?: (event: DebuggerEvent) => void;
|
|
50
|
+
onTrigger?: (event: DebuggerEvent) => void;
|
|
51
|
+
}
|
|
52
|
+
export interface ReactiveEffectOptions extends DebuggerOptions {
|
|
53
|
+
scheduler?: EffectScheduler;
|
|
54
|
+
allowRecurse?: boolean;
|
|
55
|
+
onStop?: () => void;
|
|
56
|
+
}
|
|
57
|
+
export interface ReactiveEffectRunner<T = any> {
|
|
58
|
+
(): T;
|
|
59
|
+
effect: ReactiveEffect;
|
|
60
|
+
}
|
|
61
|
+
declare let activeSub: Subscriber | undefined;
|
|
62
|
+
export declare enum EffectFlags {
|
|
63
|
+
/**
|
|
64
|
+
* ReactiveEffect only
|
|
65
|
+
*/
|
|
66
|
+
ACTIVE = 1,
|
|
67
|
+
RUNNING = 2,
|
|
68
|
+
TRACKING = 4,
|
|
69
|
+
NOTIFIED = 8,
|
|
70
|
+
DIRTY = 16,
|
|
71
|
+
ALLOW_RECURSE = 32,
|
|
72
|
+
PAUSED = 64,
|
|
73
|
+
EVALUATED = 128
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Subscriber is a type that tracks (or subscribes to) a list of deps.
|
|
77
|
+
*/
|
|
78
|
+
interface Subscriber extends DebuggerOptions {
|
|
79
|
+
}
|
|
80
|
+
export declare class ReactiveEffect<T = any> implements Subscriber, ReactiveEffectOptions {
|
|
81
|
+
fn: () => T;
|
|
82
|
+
scheduler?: EffectScheduler;
|
|
83
|
+
onStop?: () => void;
|
|
84
|
+
onTrack?: (event: DebuggerEvent) => void;
|
|
85
|
+
onTrigger?: (event: DebuggerEvent) => void;
|
|
86
|
+
constructor(fn: () => T);
|
|
87
|
+
pause(): void;
|
|
88
|
+
resume(): void;
|
|
89
|
+
run(): T;
|
|
90
|
+
stop(): void;
|
|
91
|
+
trigger(): void;
|
|
92
|
+
get dirty(): boolean;
|
|
93
|
+
}
|
|
94
|
+
export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner<T>;
|
|
95
|
+
/**
|
|
96
|
+
* Stops the effect associated with the given runner.
|
|
97
|
+
*
|
|
98
|
+
* @param runner - Association with the effect to stop tracking.
|
|
99
|
+
*/
|
|
100
|
+
export declare function stop(runner: ReactiveEffectRunner): void;
|
|
101
|
+
/**
|
|
102
|
+
* Temporarily pauses tracking.
|
|
103
|
+
*/
|
|
104
|
+
export declare function pauseTracking(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Re-enables effect tracking (if it was paused).
|
|
107
|
+
*/
|
|
108
|
+
export declare function enableTracking(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Resets the previous global effect tracking state.
|
|
111
|
+
*/
|
|
112
|
+
export declare function resetTracking(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Registers a cleanup function for the current active effect.
|
|
115
|
+
* The cleanup function is called right before the next effect run, or when the
|
|
116
|
+
* effect is stopped.
|
|
117
|
+
*
|
|
118
|
+
* Throws a warning if there is no current active effect. The warning can be
|
|
119
|
+
* suppressed by passing `true` to the second argument.
|
|
120
|
+
*
|
|
121
|
+
* @param fn - the cleanup function to be registered
|
|
122
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
123
|
+
* an active effect.
|
|
124
|
+
*/
|
|
125
|
+
export declare function onEffectCleanup(fn: () => void, failSilently?: boolean): void;
|
|
126
|
+
/**
|
|
127
|
+
* Batches reactive updates synchronously within the given function.
|
|
128
|
+
* All updates triggered inside `fn` are deferred until the function completes,
|
|
129
|
+
* then flushed together in a single batch.
|
|
130
|
+
*/
|
|
131
|
+
export declare function batch<T>(fn: () => T): T;
|
|
132
|
+
/**
|
|
133
|
+
* Executes the given function without tracking reactive dependencies.
|
|
134
|
+
* Any reactive reads inside `fn` will not trigger effect re-runs.
|
|
135
|
+
*/
|
|
136
|
+
export declare function untrack<T>(fn: () => T): T;
|
|
137
|
+
/**
|
|
138
|
+
* Returns the currently executing reactive effect, if any.
|
|
139
|
+
*/
|
|
140
|
+
export declare function getCurrentEffect(): ReactiveEffect | undefined;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Make a map and return a function for checking if a key
|
|
144
|
+
* is in that map.
|
|
145
|
+
* IMPORTANT: all calls of this function must be prefixed with
|
|
146
|
+
* \/\*#\_\_PURE\_\_\*\/
|
|
147
|
+
* So that rollup can tree-shake them if necessary.
|
|
148
|
+
*/
|
|
149
|
+
declare function makeMap(str: string): (key: string) => boolean;
|
|
150
|
+
|
|
151
|
+
declare const EMPTY_OBJ: {
|
|
152
|
+
readonly [key: string]: any;
|
|
153
|
+
};
|
|
154
|
+
declare const EMPTY_ARR: readonly never[];
|
|
155
|
+
declare const NOOP: () => void;
|
|
156
|
+
/**
|
|
157
|
+
* Always return false.
|
|
158
|
+
*/
|
|
159
|
+
declare const NO: () => boolean;
|
|
160
|
+
declare const isOn: (key: string) => boolean;
|
|
161
|
+
declare const isModelListener: (key: string) => key is `onUpdate:${string}`;
|
|
162
|
+
declare const extend: typeof Object.assign;
|
|
163
|
+
declare const remove: <T>(arr: T[], el: T) => void;
|
|
164
|
+
declare const hasOwn: (val: object, key: string | symbol) => key is keyof typeof val;
|
|
165
|
+
declare const isArray: typeof Array.isArray;
|
|
166
|
+
declare const isMap: (val: unknown) => val is Map<any, any>;
|
|
167
|
+
declare const isSet: (val: unknown) => val is Set<any>;
|
|
168
|
+
declare const isDate: (val: unknown) => val is Date;
|
|
169
|
+
declare const isRegExp: (val: unknown) => val is RegExp;
|
|
170
|
+
declare const isFunction: (val: unknown) => val is Function;
|
|
171
|
+
declare const isString: (val: unknown) => val is string;
|
|
172
|
+
declare const isSymbol: (val: unknown) => val is symbol;
|
|
173
|
+
declare const isObject: (val: unknown) => val is Record<any, any>;
|
|
174
|
+
declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
|
|
175
|
+
declare const objectToString: typeof Object.prototype.toString;
|
|
176
|
+
declare const toTypeString: (value: unknown) => string;
|
|
177
|
+
declare const toRawType: (value: unknown) => string;
|
|
178
|
+
declare const isPlainObject: (val: unknown) => val is object;
|
|
179
|
+
declare const isIntegerKey: (key: unknown) => boolean;
|
|
180
|
+
/**
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
declare const camelize: (str: string) => string;
|
|
184
|
+
/**
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
declare const hyphenate: (str: string) => string;
|
|
188
|
+
/**
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
declare const capitalize: <T extends string>(str: T) => Capitalize<T>;
|
|
192
|
+
/**
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
declare const toHandlerKey: <T extends string>(str: T) => T extends '' ? '' : `on${Capitalize<T>}`;
|
|
196
|
+
declare const hasChanged: (value: any, oldValue: any) => boolean;
|
|
197
|
+
declare const invokeArrayFns: (fns: Function[], ...arg: any[]) => void;
|
|
198
|
+
declare const def: (obj: object, key: string | symbol, value: any, writable?: boolean) => void;
|
|
199
|
+
/**
|
|
200
|
+
* "123-foo" will be parsed to 123
|
|
201
|
+
* This is used for the .number modifier in v-model
|
|
202
|
+
*/
|
|
203
|
+
declare const looseToNumber: (val: any) => any;
|
|
204
|
+
/**
|
|
205
|
+
* Only concerns number-like strings
|
|
206
|
+
* "123-foo" will be returned as-is
|
|
207
|
+
*/
|
|
208
|
+
declare const toNumber: (val: any) => any;
|
|
209
|
+
declare const getGlobalThis: () => any;
|
|
210
|
+
declare function genPropsAccessExp(name: string): string;
|
|
211
|
+
declare function genCacheKey(source: string, options: any): string;
|
|
212
|
+
|
|
213
|
+
type Prettify<T> = {
|
|
214
|
+
[K in keyof T]: T[K];
|
|
215
|
+
} & {};
|
|
216
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
217
|
+
type LooseRequired<T> = {
|
|
218
|
+
[P in keyof (T & Required<T>)]: T[P];
|
|
219
|
+
};
|
|
220
|
+
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
221
|
+
type IsKeyValues<T, K = string> = IfAny<T, false, T extends object ? (keyof T extends K ? true : false) : false>;
|
|
222
|
+
/**
|
|
223
|
+
* Utility for extracting the parameters from a function overload (for typed emits)
|
|
224
|
+
* https://github.com/microsoft/TypeScript/issues/32164#issuecomment-1146737709
|
|
225
|
+
*/
|
|
226
|
+
type OverloadParameters<T extends (...args: any[]) => any> = Parameters<OverloadUnion<T>>;
|
|
227
|
+
type OverloadProps<TOverload> = Pick<TOverload, keyof TOverload>;
|
|
228
|
+
type OverloadUnionRecursive<TOverload, TPartialOverload = unknown> = TOverload extends (...args: infer TArgs) => infer TReturn ? TPartialOverload extends TOverload ? never : OverloadUnionRecursive<TPartialOverload & TOverload, TPartialOverload & ((...args: TArgs) => TReturn) & OverloadProps<TOverload>> | ((...args: TArgs) => TReturn) : never;
|
|
229
|
+
type OverloadUnion<TOverload extends (...args: any[]) => any> = Exclude<OverloadUnionRecursive<(() => never) & TOverload>, TOverload extends () => never ? never : () => never>;
|
|
230
|
+
|
|
231
|
+
import { ReactiveFlags } from './constants';
|
|
232
|
+
import type { RawSymbol, Ref, UnwrapRefSimple } from './ref';
|
|
233
|
+
interface Target {
|
|
234
|
+
[ReactiveFlags.SKIP]?: boolean;
|
|
235
|
+
[ReactiveFlags.IS_REACTIVE]?: boolean;
|
|
236
|
+
[ReactiveFlags.IS_READONLY]?: boolean;
|
|
237
|
+
[ReactiveFlags.IS_SHALLOW]?: boolean;
|
|
238
|
+
[ReactiveFlags.RAW]?: any;
|
|
239
|
+
}
|
|
240
|
+
declare const reactiveMap: WeakMap<Target, any>;
|
|
241
|
+
declare const shallowReactiveMap: WeakMap<Target, any>;
|
|
242
|
+
declare const readonlyMap: WeakMap<Target, any>;
|
|
243
|
+
declare const shallowReadonlyMap: WeakMap<Target, any>;
|
|
244
|
+
type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
|
|
245
|
+
declare const ReactiveMarkerSymbol: unique symbol;
|
|
246
|
+
interface ReactiveMarker {
|
|
247
|
+
[ReactiveMarkerSymbol]?: void;
|
|
248
|
+
}
|
|
249
|
+
type Reactive<T> = UnwrapNestedRefs<T> & (T extends readonly any[] ? ReactiveMarker : {});
|
|
250
|
+
/**
|
|
251
|
+
* Returns a reactive proxy of the object.
|
|
252
|
+
*
|
|
253
|
+
* The reactive conversion is "deep": it affects all nested properties. A
|
|
254
|
+
* reactive object also deeply unwraps any properties that are refs while
|
|
255
|
+
* maintaining reactivity.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```js
|
|
259
|
+
* const obj = reactive({ count: 0 })
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @param target - The source object.
|
|
263
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#reactive}
|
|
264
|
+
*/
|
|
265
|
+
declare function reactive<T extends object>(target: T): Reactive<T>;
|
|
266
|
+
declare class ShallowReactiveBrandClass {
|
|
267
|
+
private __shallowReactiveBrand?;
|
|
268
|
+
}
|
|
269
|
+
type ShallowReactiveBrand = ShallowReactiveBrandClass;
|
|
270
|
+
type ShallowReactive<T> = T & ShallowReactiveBrand;
|
|
271
|
+
/**
|
|
272
|
+
* Shallow version of {@link reactive}.
|
|
273
|
+
*
|
|
274
|
+
* Unlike {@link reactive}, there is no deep conversion: only root-level
|
|
275
|
+
* properties are reactive for a shallow reactive object. Property values are
|
|
276
|
+
* stored and exposed as-is - this also means properties with ref values will
|
|
277
|
+
* not be automatically unwrapped.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```js
|
|
281
|
+
* const state = shallowReactive({
|
|
282
|
+
* foo: 1,
|
|
283
|
+
* nested: {
|
|
284
|
+
* bar: 2
|
|
285
|
+
* }
|
|
286
|
+
* })
|
|
287
|
+
*
|
|
288
|
+
* // mutating state's own properties is reactive
|
|
289
|
+
* state.foo++
|
|
290
|
+
*
|
|
291
|
+
* // ...but does not convert nested objects
|
|
292
|
+
* isReactive(state.nested) // false
|
|
293
|
+
*
|
|
294
|
+
* // NOT reactive
|
|
295
|
+
* state.nested.bar++
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* @param target - The source object.
|
|
299
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive}
|
|
300
|
+
*/
|
|
301
|
+
declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
|
|
302
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
303
|
+
type Builtin = Primitive | Function | Date | Error | RegExp;
|
|
304
|
+
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 {} ? {
|
|
305
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
306
|
+
} : Readonly<T>;
|
|
307
|
+
/**
|
|
308
|
+
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
309
|
+
* the original.
|
|
310
|
+
*
|
|
311
|
+
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
312
|
+
* well. It also has the same ref-unwrapping behavior as {@link reactive},
|
|
313
|
+
* except the unwrapped values will also be made readonly.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```js
|
|
317
|
+
* const original = reactive({ count: 0 })
|
|
318
|
+
*
|
|
319
|
+
* const copy = readonly(original)
|
|
320
|
+
*
|
|
321
|
+
* watchEffect(() => {
|
|
322
|
+
* // works for reactivity tracking
|
|
323
|
+
* console.log(copy.count)
|
|
324
|
+
* })
|
|
325
|
+
*
|
|
326
|
+
* // mutating original will trigger watchers relying on the copy
|
|
327
|
+
* original.count++
|
|
328
|
+
*
|
|
329
|
+
* // mutating the copy will fail and result in a warning
|
|
330
|
+
* copy.count++ // warning!
|
|
331
|
+
* ```
|
|
332
|
+
*
|
|
333
|
+
* @param target - The source object.
|
|
334
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
|
|
335
|
+
*/
|
|
336
|
+
declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>>;
|
|
337
|
+
/**
|
|
338
|
+
* Shallow version of {@link readonly}.
|
|
339
|
+
*
|
|
340
|
+
* Unlike {@link readonly}, there is no deep conversion: only root-level
|
|
341
|
+
* properties are made readonly. Property values are stored and exposed as-is -
|
|
342
|
+
* this also means properties with ref values will not be automatically
|
|
343
|
+
* unwrapped.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```js
|
|
347
|
+
* const state = shallowReadonly({
|
|
348
|
+
* foo: 1,
|
|
349
|
+
* nested: {
|
|
350
|
+
* bar: 2
|
|
351
|
+
* }
|
|
352
|
+
* })
|
|
353
|
+
*
|
|
354
|
+
* // mutating state's own properties will fail
|
|
355
|
+
* state.foo++
|
|
356
|
+
*
|
|
357
|
+
* // ...but works on nested objects
|
|
358
|
+
* isReadonly(state.nested) // false
|
|
359
|
+
*
|
|
360
|
+
* // works
|
|
361
|
+
* state.nested.bar++
|
|
362
|
+
* ```
|
|
363
|
+
*
|
|
364
|
+
* @param target - The source object.
|
|
365
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly}
|
|
366
|
+
*/
|
|
367
|
+
declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
|
|
368
|
+
/**
|
|
369
|
+
* Checks if an object is a proxy created by {@link reactive} or
|
|
370
|
+
* {@link shallowReactive} (or {@link ref} in some cases).
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```js
|
|
374
|
+
* isReactive(reactive({})) // => true
|
|
375
|
+
* isReactive(readonly(reactive({}))) // => true
|
|
376
|
+
* isReactive(ref({}).value) // => true
|
|
377
|
+
* isReactive(readonly(ref({})).value) // => true
|
|
378
|
+
* isReactive(ref(true)) // => false
|
|
379
|
+
* isReactive(shallowRef({}).value) // => false
|
|
380
|
+
* isReactive(shallowReactive({})) // => true
|
|
381
|
+
* ```
|
|
382
|
+
*
|
|
383
|
+
* @param value - The value to check.
|
|
384
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
|
|
385
|
+
*/
|
|
386
|
+
declare function isReactive(value: unknown): boolean;
|
|
387
|
+
/**
|
|
388
|
+
* Checks whether the passed value is a readonly object. The properties of a
|
|
389
|
+
* readonly object can change, but they can't be assigned directly via the
|
|
390
|
+
* passed object.
|
|
391
|
+
*
|
|
392
|
+
* The proxies created by {@link readonly} and {@link shallowReadonly} are
|
|
393
|
+
* both considered readonly, as is a computed ref without a set function.
|
|
394
|
+
*
|
|
395
|
+
* @param value - The value to check.
|
|
396
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
|
|
397
|
+
*/
|
|
398
|
+
declare function isReadonly(value: unknown): boolean;
|
|
399
|
+
declare function isShallow(value: unknown): boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Checks if an object is a proxy created by {@link reactive},
|
|
402
|
+
* {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
|
|
403
|
+
*
|
|
404
|
+
* @param value - The value to check.
|
|
405
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
|
|
406
|
+
*/
|
|
407
|
+
declare function isProxy(value: any): boolean;
|
|
408
|
+
/**
|
|
409
|
+
* Returns the raw, original object of a Vue-created proxy.
|
|
410
|
+
*
|
|
411
|
+
* `toRaw()` can return the original object from proxies created by
|
|
412
|
+
* {@link reactive}, {@link readonly}, {@link shallowReactive} or
|
|
413
|
+
* {@link shallowReadonly}.
|
|
414
|
+
*
|
|
415
|
+
* This is an escape hatch that can be used to temporarily read without
|
|
416
|
+
* incurring proxy access / tracking overhead or write without triggering
|
|
417
|
+
* changes. It is **not** recommended to hold a persistent reference to the
|
|
418
|
+
* original object. Use with caution.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```js
|
|
422
|
+
* const foo = {}
|
|
423
|
+
* const reactiveFoo = reactive(foo)
|
|
424
|
+
*
|
|
425
|
+
* console.log(toRaw(reactiveFoo) === foo) // true
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @param observed - The object for which the "raw" value is requested.
|
|
429
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
|
|
430
|
+
*/
|
|
431
|
+
declare function toRaw<T>(observed: T): T;
|
|
432
|
+
type Raw<T> = T & {
|
|
433
|
+
[RawSymbol]?: true;
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Marks an object so that it will never be converted to a proxy. Returns the
|
|
437
|
+
* object itself.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```js
|
|
441
|
+
* const foo = markRaw({})
|
|
442
|
+
* console.log(isReactive(reactive(foo))) // false
|
|
443
|
+
*
|
|
444
|
+
* // also works when nested inside other reactive objects
|
|
445
|
+
* const bar = reactive({ foo })
|
|
446
|
+
* console.log(isReactive(bar.foo)) // false
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* **Warning:** `markRaw()` together with the shallow APIs such as
|
|
450
|
+
* {@link shallowReactive} allow you to selectively opt-out of the default
|
|
451
|
+
* deep reactive/readonly conversion and embed raw, non-proxied objects in your
|
|
452
|
+
* state graph.
|
|
453
|
+
*
|
|
454
|
+
* @param value - The object to be marked as "raw".
|
|
455
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
|
|
456
|
+
*/
|
|
457
|
+
declare function markRaw<T extends object>(value: T): Raw<T>;
|
|
458
|
+
/**
|
|
459
|
+
* Returns a reactive proxy of the given value (if possible).
|
|
460
|
+
*
|
|
461
|
+
* If the given value is not an object, the original value itself is returned.
|
|
462
|
+
*
|
|
463
|
+
* @param value - The value for which a reactive proxy shall be created.
|
|
464
|
+
*/
|
|
465
|
+
declare const toReactive: <T extends unknown>(value: T) => T;
|
|
466
|
+
/**
|
|
467
|
+
* Returns a readonly proxy of the given value (if possible).
|
|
468
|
+
*
|
|
469
|
+
* If the given value is not an object, the original value itself is returned.
|
|
470
|
+
*
|
|
471
|
+
* @param value - The value for which a readonly proxy shall be created.
|
|
472
|
+
*/
|
|
473
|
+
declare const toReadonly: <T extends unknown>(value: T) => DeepReadonly<T>;
|
|
474
|
+
|
|
475
|
+
import { type IfAny } from '@zeus-js/shared';
|
|
476
|
+
import { type Builtin, type ShallowReactiveBrand } from './reactive';
|
|
477
|
+
import type { ComputedRef, WritableComputedRef } from './computed';
|
|
478
|
+
declare const RefSymbol: unique symbol;
|
|
479
|
+
declare const RawSymbol: unique symbol;
|
|
480
|
+
interface Ref<T = any, S = T> {
|
|
481
|
+
get value(): T;
|
|
482
|
+
set value(_: S);
|
|
483
|
+
/**
|
|
484
|
+
* Type differentiator only.
|
|
485
|
+
* We need this to be in public d.ts but don't want it to show up in IDE
|
|
486
|
+
* autocomplete, so we use a private Symbol instead.
|
|
487
|
+
*/
|
|
488
|
+
[RefSymbol]: true;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Checks if a value is a ref object.
|
|
492
|
+
*
|
|
493
|
+
* @param r - The value to inspect.
|
|
494
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isref}
|
|
495
|
+
*/
|
|
496
|
+
declare function isRef<T>(r: Ref<T> | unknown): r is Ref<T>;
|
|
497
|
+
/**
|
|
498
|
+
* Takes an inner value and returns a reactive and mutable ref object, which
|
|
499
|
+
* has a single property `.value` that points to the inner value.
|
|
500
|
+
*
|
|
501
|
+
* @param value - The object to wrap in the ref.
|
|
502
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#ref}
|
|
503
|
+
*/
|
|
504
|
+
declare function ref<T>(value: T): [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T>;
|
|
505
|
+
declare function ref<T = any>(): Ref<T | undefined>;
|
|
506
|
+
declare const ShallowRefMarker: unique symbol;type ShallowRef<T = any, S = T> = Ref<T, S> & {
|
|
507
|
+
[ShallowRefMarker]?: true;
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* Shallow version of {@link ref}.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```js
|
|
514
|
+
* const state = shallowRef({ count: 1 })
|
|
515
|
+
*
|
|
516
|
+
* // does NOT trigger change
|
|
517
|
+
* state.value.count = 2
|
|
518
|
+
*
|
|
519
|
+
* // does trigger change
|
|
520
|
+
* state.value = { count: 2 }
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* @param value - The "inner value" for the shallow ref.
|
|
524
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowref}
|
|
525
|
+
*/
|
|
526
|
+
declare function shallowRef<T>(value: T): Ref extends T ? T extends Ref ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T> : ShallowRef<T>;
|
|
527
|
+
declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
|
|
528
|
+
/**
|
|
529
|
+
* Force trigger effects that depends on a shallow ref. This is typically used
|
|
530
|
+
* after making deep mutations to the inner value of a shallow ref.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```js
|
|
534
|
+
* const shallow = shallowRef({
|
|
535
|
+
* greet: 'Hello, world'
|
|
536
|
+
* })
|
|
537
|
+
*
|
|
538
|
+
* // Logs "Hello, world" once for the first run-through
|
|
539
|
+
* watchEffect(() => {
|
|
540
|
+
* console.log(shallow.value.greet)
|
|
541
|
+
* })
|
|
542
|
+
*
|
|
543
|
+
* // This won't trigger the effect because the ref is shallow
|
|
544
|
+
* shallow.value.greet = 'Hello, universe'
|
|
545
|
+
*
|
|
546
|
+
* // Logs "Hello, universe"
|
|
547
|
+
* triggerRef(shallow)
|
|
548
|
+
* ```
|
|
549
|
+
*
|
|
550
|
+
* @param ref - The ref whose tied effects shall be executed.
|
|
551
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
|
|
552
|
+
*/
|
|
553
|
+
declare function triggerRef(ref: Ref): void;
|
|
554
|
+
type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>;
|
|
555
|
+
type MaybeRefOrGetter<T = any> = MaybeRef<T> | ComputedRef<T> | (() => T);
|
|
556
|
+
/**
|
|
557
|
+
* Returns the inner value if the argument is a ref, otherwise return the
|
|
558
|
+
* argument itself. This is a sugar function for
|
|
559
|
+
* `val = isRef(val) ? val.value : val`.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```js
|
|
563
|
+
* function useFoo(x: number | Ref<number>) {
|
|
564
|
+
* const unwrapped = unref(x)
|
|
565
|
+
* // unwrapped is guaranteed to be number now
|
|
566
|
+
* }
|
|
567
|
+
* ```
|
|
568
|
+
*
|
|
569
|
+
* @param ref - Ref or plain value to be converted into the plain value.
|
|
570
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
|
|
571
|
+
*/
|
|
572
|
+
declare function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T;
|
|
573
|
+
/**
|
|
574
|
+
* Normalizes values / refs / getters to values.
|
|
575
|
+
* This is similar to {@link unref}, except that it also normalizes getters.
|
|
576
|
+
* If the argument is a getter, it will be invoked and its return value will
|
|
577
|
+
* be returned.
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```js
|
|
581
|
+
* toValue(1) // 1
|
|
582
|
+
* toValue(ref(1)) // 1
|
|
583
|
+
* toValue(() => 1) // 1
|
|
584
|
+
* ```
|
|
585
|
+
*
|
|
586
|
+
* @param source - A getter, an existing ref, or a non-function value.
|
|
587
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
|
|
588
|
+
*/
|
|
589
|
+
declare function toValue<T>(source: MaybeRefOrGetter<T>): T;
|
|
590
|
+
/**
|
|
591
|
+
* Returns a proxy for the given object that shallowly unwraps properties that
|
|
592
|
+
* are refs. If the object already is reactive, it's returned as-is. If not, a
|
|
593
|
+
* new reactive proxy is created.
|
|
594
|
+
*
|
|
595
|
+
* @param objectWithRefs - Either an already-reactive object or a simple object
|
|
596
|
+
* that contains refs.
|
|
597
|
+
*/
|
|
598
|
+
declare function proxyRefs<T extends object>(objectWithRefs: T): ShallowUnwrapRef<T>;
|
|
599
|
+
type CustomRefFactory<T, S = T> = (track: () => void, trigger: () => void) => {
|
|
600
|
+
get: () => T;
|
|
601
|
+
set: (value: S) => void;
|
|
602
|
+
};
|
|
603
|
+
/**
|
|
604
|
+
* Creates a customized ref with explicit control over its dependency tracking
|
|
605
|
+
* and updates triggering.
|
|
606
|
+
*
|
|
607
|
+
* @param factory - The function that receives the `track` and `trigger` callbacks.
|
|
608
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref}
|
|
609
|
+
*/
|
|
610
|
+
declare function customRef<T, S = T>(factory: CustomRefFactory<T, S>): Ref<T, S>;
|
|
611
|
+
type ToRefs<T = any> = {
|
|
612
|
+
[K in keyof T]: ToRef<T[K]>;
|
|
613
|
+
};
|
|
614
|
+
type ArrayStringKey<T> = T extends readonly any[] ? number extends T['length'] ? `${number}` : never : never;
|
|
615
|
+
type ToRefKey<T> = keyof T | ArrayStringKey<T>;
|
|
616
|
+
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;
|
|
617
|
+
/**
|
|
618
|
+
* Converts a reactive object to a plain object where each property of the
|
|
619
|
+
* resulting object is a ref pointing to the corresponding property of the
|
|
620
|
+
* original object. Each individual ref is created using {@link toRef}.
|
|
621
|
+
*
|
|
622
|
+
* @param object - Reactive object to be made into an object of linked refs.
|
|
623
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
|
|
624
|
+
*/
|
|
625
|
+
declare function toRefs<T extends object>(object: T): ToRefs<T>;
|
|
626
|
+
type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>;
|
|
627
|
+
/**
|
|
628
|
+
* Used to normalize values / refs / getters into refs.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```js
|
|
632
|
+
* // returns existing refs as-is
|
|
633
|
+
* toRef(existingRef)
|
|
634
|
+
*
|
|
635
|
+
* // creates a ref that calls the getter on .value access
|
|
636
|
+
* toRef(() => props.foo)
|
|
637
|
+
*
|
|
638
|
+
* // creates normal refs from non-function values
|
|
639
|
+
* // equivalent to ref(1)
|
|
640
|
+
* toRef(1)
|
|
641
|
+
* ```
|
|
642
|
+
*
|
|
643
|
+
* Can also be used to create a ref for a property on a source reactive object.
|
|
644
|
+
* The created ref is synced with its source property: mutating the source
|
|
645
|
+
* property will update the ref, and vice-versa.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```js
|
|
649
|
+
* const state = reactive({
|
|
650
|
+
* foo: 1,
|
|
651
|
+
* bar: 2
|
|
652
|
+
* })
|
|
653
|
+
*
|
|
654
|
+
* const fooRef = toRef(state, 'foo')
|
|
655
|
+
*
|
|
656
|
+
* // mutating the ref updates the original
|
|
657
|
+
* fooRef.value++
|
|
658
|
+
* console.log(state.foo) // 2
|
|
659
|
+
*
|
|
660
|
+
* // mutating the original also updates the ref
|
|
661
|
+
* state.foo++
|
|
662
|
+
* console.log(fooRef.value) // 3
|
|
663
|
+
* ```
|
|
664
|
+
*
|
|
665
|
+
* @param source - A getter, an existing ref, a non-function value, or a
|
|
666
|
+
* reactive object to create a property ref from.
|
|
667
|
+
* @param [key] - (optional) Name of the property in the reactive object.
|
|
668
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#toref}
|
|
669
|
+
*/
|
|
670
|
+
declare function toRef<T>(value: T): T extends () => infer R ? Readonly<Ref<R>> : T extends Ref ? T : Ref<UnwrapRef<T>>;
|
|
671
|
+
declare function toRef<T extends object, K extends ToRefKey<T>>(object: T, key: K): ToRef<ToRefValue<T, K>>;
|
|
672
|
+
declare function toRef<T extends object, K extends ToRefKey<T>>(object: T, key: K, defaultValue: ToRefValue<T, K>): ToRef<Exclude<ToRefValue<T, K>, undefined>>;
|
|
673
|
+
/**
|
|
674
|
+
* This is a special exported interface for other packages to declare
|
|
675
|
+
* additional types that should bail out for ref unwrapping. For example
|
|
676
|
+
* \@vue/runtime-dom can declare it like so in its d.ts:
|
|
677
|
+
*
|
|
678
|
+
* ``` ts
|
|
679
|
+
* declare module '@vue/reactivity' {
|
|
680
|
+
* export interface RefUnwrapBailTypes {
|
|
681
|
+
* runtimeDOMBailTypes: Node | Window
|
|
682
|
+
* }
|
|
683
|
+
* }
|
|
684
|
+
* ```
|
|
685
|
+
*/
|
|
686
|
+
interface RefUnwrapBailTypes {
|
|
687
|
+
}
|
|
688
|
+
type ShallowUnwrapRef<T> = T extends ShallowReactiveBrand ? T : {
|
|
689
|
+
[K in keyof T]: DistributeRef<T[K]>;
|
|
690
|
+
};
|
|
691
|
+
type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T;
|
|
692
|
+
type UnwrapRef<T> = T extends ShallowRef<infer V, unknown> ? V : T extends Ref<infer V, unknown> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
|
|
693
|
+
type UnwrapRefSimple<T> = T extends Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
|
|
694
|
+
[RawSymbol]?: true;
|
|
695
|
+
} ? 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> ? {
|
|
696
|
+
[K in keyof T]: UnwrapRefSimple<T[K]>;
|
|
697
|
+
} : T extends object ? {
|
|
698
|
+
[P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>;
|
|
699
|
+
} : T;
|
|
700
|
+
|
|
701
|
+
import { type DebuggerEvent, type DebuggerOptions, type Subscriber } from './effect';
|
|
702
|
+
import type { Ref } from './ref';
|
|
703
|
+
declare const ComputedRefSymbol: unique symbol;
|
|
704
|
+
declare const WritableComputedRefSymbol: unique symbol;
|
|
705
|
+
interface BaseComputedRef<T, S = T> extends Ref<T, S> {
|
|
706
|
+
[ComputedRefSymbol]: true;
|
|
707
|
+
/**
|
|
708
|
+
* @deprecated computed no longer uses effect
|
|
709
|
+
*/
|
|
710
|
+
effect: ComputedRefImpl;
|
|
711
|
+
}
|
|
712
|
+
export interface ComputedRef<T = any> extends BaseComputedRef<T> {
|
|
713
|
+
readonly value: T;
|
|
714
|
+
}
|
|
715
|
+
export interface WritableComputedRef<T, S = T> extends BaseComputedRef<T, S> {
|
|
716
|
+
[WritableComputedRefSymbol]: true;
|
|
717
|
+
}
|
|
718
|
+
export type ComputedGetter<T> = (oldValue?: T) => T;
|
|
719
|
+
export type ComputedSetter<T> = (newValue: T) => void;
|
|
720
|
+
export interface WritableComputedOptions<T, S = T> {
|
|
721
|
+
get: ComputedGetter<T>;
|
|
722
|
+
set: ComputedSetter<S>;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* @private exported by @vue/reactivity for Vue core use, but not exported from
|
|
726
|
+
* the main vue package
|
|
727
|
+
*/
|
|
728
|
+
export declare class ComputedRefImpl<T = any> implements Subscriber {
|
|
729
|
+
fn: ComputedGetter<T>;
|
|
730
|
+
private readonly setter;
|
|
731
|
+
effect: this;
|
|
732
|
+
onTrack?: (event: DebuggerEvent) => void;
|
|
733
|
+
onTrigger?: (event: DebuggerEvent) => void;
|
|
734
|
+
constructor(fn: ComputedGetter<T>, setter: ComputedSetter<T> | undefined, isSSR: boolean);
|
|
735
|
+
get value(): T;
|
|
736
|
+
set value(newValue: T);
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Takes a getter function and returns a readonly reactive ref object for the
|
|
740
|
+
* returned value from the getter. It can also take an object with get and set
|
|
741
|
+
* functions to create a writable ref object.
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* ```js
|
|
745
|
+
* // Creating a readonly computed ref:
|
|
746
|
+
* const count = ref(1)
|
|
747
|
+
* const plusOne = computed(() => count.value + 1)
|
|
748
|
+
*
|
|
749
|
+
* console.log(plusOne.value) // 2
|
|
750
|
+
* plusOne.value++ // error
|
|
751
|
+
* ```
|
|
752
|
+
*
|
|
753
|
+
* ```js
|
|
754
|
+
* // Creating a writable computed ref:
|
|
755
|
+
* const count = ref(1)
|
|
756
|
+
* const plusOne = computed({
|
|
757
|
+
* get: () => count.value + 1,
|
|
758
|
+
* set: (val) => {
|
|
759
|
+
* count.value = val - 1
|
|
760
|
+
* }
|
|
761
|
+
* })
|
|
762
|
+
*
|
|
763
|
+
* plusOne.value = 1
|
|
764
|
+
* console.log(count.value) // 0
|
|
765
|
+
* ```
|
|
766
|
+
*
|
|
767
|
+
* @param getter - Function that produces the next value.
|
|
768
|
+
* @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
|
|
769
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#computed}
|
|
770
|
+
*/
|
|
771
|
+
export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
|
|
772
|
+
export declare function computed<T, S = T>(options: WritableComputedOptions<T, S>, debugOptions?: DebuggerOptions): WritableComputedRef<T, S>;
|
|
773
|
+
|
|
774
|
+
export declare function queueJob(job: () => void): void;
|
|
775
|
+
export declare function flushJobs(): void;
|
|
776
|
+
export declare function nextTick(): Promise<void>;
|
|
777
|
+
|
|
778
|
+
import { type TrackOpTypes, TriggerOpTypes } from './constants';
|
|
779
|
+
/**
|
|
780
|
+
* Incremented every time a reactive change happens
|
|
781
|
+
* This is used to give computed a fast path to avoid re-compute when nothing
|
|
782
|
+
* has changed.
|
|
783
|
+
*/
|
|
784
|
+
declare let globalVersion: number;
|
|
785
|
+
type KeyToDepMap = Map<any, Dep>;
|
|
786
|
+
declare const targetMap: WeakMap<object, KeyToDepMap>;
|
|
787
|
+
export declare const ITERATE_KEY: unique symbol;
|
|
788
|
+
export declare const MAP_KEY_ITERATE_KEY: unique symbol;
|
|
789
|
+
export declare const ARRAY_ITERATE_KEY: unique symbol;
|
|
790
|
+
/**
|
|
791
|
+
* Tracks access to a reactive property.
|
|
792
|
+
*
|
|
793
|
+
* This will check which effect is running at the moment and record it as dep
|
|
794
|
+
* which records all effects that depend on the reactive property.
|
|
795
|
+
*
|
|
796
|
+
* @param target - Object holding the reactive property.
|
|
797
|
+
* @param type - Defines the type of access to the reactive property.
|
|
798
|
+
* @param key - Identifier of the reactive property to track.
|
|
799
|
+
*/
|
|
800
|
+
export declare function track(target: object, type: TrackOpTypes, key: unknown): void;
|
|
801
|
+
/**
|
|
802
|
+
* Finds all deps associated with the target (or a specific property) and
|
|
803
|
+
* triggers the effects stored within.
|
|
804
|
+
*
|
|
805
|
+
* @param target - The reactive object.
|
|
806
|
+
* @param type - Defines the type of the operation that needs to trigger effects.
|
|
807
|
+
* @param key - Can be used to target a specific reactive property in the target object.
|
|
808
|
+
*/
|
|
809
|
+
export declare function trigger(target: object, type: TriggerOpTypes, key?: unknown, newValue?: unknown, oldValue?: unknown, oldTarget?: Map<unknown, unknown> | Set<unknown>): void;
|
|
810
|
+
declare function getDepFromReactive(object: any, key: string | number | symbol): Dep | undefined;
|
|
811
|
+
|
|
812
|
+
declare let activeEffectScope: EffectScope | undefined;
|
|
813
|
+
export declare class EffectScope {
|
|
814
|
+
detached: boolean;
|
|
815
|
+
private _isPaused;
|
|
816
|
+
private _warnOnRun;
|
|
817
|
+
readonly __v_skip = true;
|
|
818
|
+
constructor(detached?: boolean);
|
|
819
|
+
get active(): boolean;
|
|
820
|
+
pause(): void;
|
|
821
|
+
/**
|
|
822
|
+
* Resumes the effect scope, including all child scopes and effects.
|
|
823
|
+
*/
|
|
824
|
+
resume(): void;
|
|
825
|
+
run<T>(fn: () => T): T | undefined;
|
|
826
|
+
prevScope: EffectScope | undefined;
|
|
827
|
+
stop(fromParent?: boolean): void;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
831
|
+
* computed and watchers) created within it so that these effects can be
|
|
832
|
+
* disposed together. For detailed use cases of this API, please consult its
|
|
833
|
+
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
834
|
+
*
|
|
835
|
+
* @param detached - Can be used to create a "detached" effect scope.
|
|
836
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
|
|
837
|
+
*/
|
|
838
|
+
export declare function effectScope(detached?: boolean): EffectScope;
|
|
839
|
+
/**
|
|
840
|
+
* Returns the current active effect scope if there is one.
|
|
841
|
+
*
|
|
842
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
843
|
+
*/
|
|
844
|
+
export declare function getCurrentScope(): EffectScope | undefined;
|
|
845
|
+
/**
|
|
846
|
+
* Registers a dispose callback on the current active effect scope. The
|
|
847
|
+
* callback will be invoked when the associated effect scope is stopped.
|
|
848
|
+
*
|
|
849
|
+
* @param fn - The callback function to attach to the scope's cleanup.
|
|
850
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
851
|
+
*/
|
|
852
|
+
export declare function onScopeDispose(fn: () => void, failSilently?: boolean): void;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Track array iteration and return:
|
|
856
|
+
* - if input is reactive: a cloned raw array with reactive values
|
|
857
|
+
* - if input is non-reactive or shallowReactive: the original raw array
|
|
858
|
+
*/
|
|
859
|
+
export declare function reactiveReadArray<T>(array: T[]): T[];
|
|
860
|
+
/**
|
|
861
|
+
* Track array iteration and return raw array
|
|
862
|
+
*/
|
|
863
|
+
export declare function shallowReadArray<T>(arr: T[]): T[];
|
|
864
|
+
declare const arrayInstrumentations: Record<string | symbol, Function>;
|
|
865
|
+
|
|
866
|
+
import { type DebuggerOptions, ReactiveEffect } from './effect';
|
|
867
|
+
import { type Ref } from './ref';
|
|
868
|
+
import type { ComputedRef } from './computed';
|
|
869
|
+
export declare enum WatchErrorCodes {
|
|
870
|
+
WATCH_GETTER = 2,
|
|
871
|
+
WATCH_CALLBACK = 3,
|
|
872
|
+
WATCH_CLEANUP = 4
|
|
873
|
+
}
|
|
874
|
+
export type WatchEffect = (onCleanup: OnCleanup) => void;
|
|
875
|
+
export type WatchSource<T = any> = Ref<T, any> | ComputedRef<T> | (() => T);
|
|
876
|
+
export type WatchCallback<V = any, OV = any> = (value: V, oldValue: OV, onCleanup: OnCleanup) => any;
|
|
877
|
+
export type OnCleanup = (cleanupFn: () => void) => void;
|
|
878
|
+
export interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
|
|
879
|
+
immediate?: Immediate;
|
|
880
|
+
deep?: boolean | number;
|
|
881
|
+
once?: boolean;
|
|
882
|
+
scheduler?: WatchScheduler;
|
|
883
|
+
onWarn?: (msg: string, ...args: any[]) => void;
|
|
884
|
+
}
|
|
885
|
+
export type WatchStopHandle = () => void;
|
|
886
|
+
export interface WatchHandle extends WatchStopHandle {
|
|
887
|
+
pause: () => void;
|
|
888
|
+
resume: () => void;
|
|
889
|
+
stop: () => void;
|
|
890
|
+
}
|
|
891
|
+
export type WatchScheduler = (job: () => void, isFirstRun: boolean) => void;
|
|
892
|
+
/**
|
|
893
|
+
* Returns the current active effect if there is one.
|
|
894
|
+
*/
|
|
895
|
+
export declare function getCurrentWatcher(): ReactiveEffect<any> | undefined;
|
|
896
|
+
/**
|
|
897
|
+
* Registers a cleanup callback on the current active effect. This
|
|
898
|
+
* registered cleanup callback will be invoked right before the
|
|
899
|
+
* associated effect re-runs.
|
|
900
|
+
*
|
|
901
|
+
* @param cleanupFn - The callback function to attach to the effect's cleanup.
|
|
902
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
903
|
+
* an active effect.
|
|
904
|
+
* @param owner - The effect that this cleanup function should be attached to.
|
|
905
|
+
* By default, the current active effect.
|
|
906
|
+
*/
|
|
907
|
+
export declare function onWatcherCleanup(cleanupFn: () => void, failSilently?: boolean, owner?: ReactiveEffect | undefined): void;
|
|
908
|
+
export declare function watch(source: WatchSource | WatchSource[] | WatchEffect | object, cb?: WatchCallback | null, options?: WatchOptions): WatchHandle;
|
|
909
|
+
export declare function traverse(value: unknown, depth?: number, seen?: Map<unknown, number>): unknown;
|
|
910
|
+
|
|
911
|
+
export declare function onCleanup(fn: () => void): void;
|
|
912
|
+
|
|
913
|
+
export { EffectScope as Scope, effectScope as scope, };
|
|
914
|
+
|