Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reactivity.d.ts 23KB

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