1export enum ReactiveFlags {
2 SKIP = '__v_skip',
3 IS_REACTIVE = '__v_isReactive',
4 IS_READONLY = '__v_isReadonly',
5 IS_SHALLOW = '__v_isShallow',
6 RAW = '__v_raw',
7}
8
9
10 * Checks if an object is a proxy created by {@link reactive()} or
11 * {@link shallowReactive()} (or {@link ref()} in some cases).
12 *
13 * @example
14 * ```js
15 * isReactive(reactive({})) // => true
16 * isReactive(readonly(reactive({}))) // => true
17 * isReactive(ref({}).value) // => true
18 * isReactive(readonly(ref({})).value) // => true
19 * isReactive(ref(true)) // => false
20 * isReactive(shallowRef({}).value) // => false
21 * isReactive(shallowReactive({})) // => true
22 * ```
23 *
24 * @param value - The value to check.
25 * @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
26 */
27export function isReactive(value: unknown): boolean {
28 if (isReadonly(value)) {
29 return isReactive((value as Target)[ReactiveFlags.RAW])
30 }
31 return !!(value && (value as Target)[ReactiveFlags.IS_REACTIVE])
32}