UNPKG

@cran/lib.vue.ref

Version:

Vue Reactivity Extensions

40 lines (36 loc) 1.1 kB
/* eslint-disable @typescript-eslint/unified-signatures */ import type { MaybeWrapped } from "./MaybeWrapped"; import type { RefLike } from "./RefLike"; import type { Thunk } from "./Thunk"; import { isRef } from "vue"; /** * Warning! Using `unwrap` on a value which can * only ever be a ref is not advised. * Instead use `wrapped.value`. * @since 0.0.1 * @category Utility * @deprecated */ export function unwrap<T> ( wrapped: RefLike<T> ): T; /** * Warning! Using `unwrap` on a value which can * only ever be a thunk is not advised. * Instead use `wrapped()`. * @since 0.0.1 * @category Utility * @deprecated */ export function unwrap<T> ( wrapped: Thunk<T> ): T; /** * Return the inner value if the argument is a ref, * otherwise return the argument itself. * Additionally allows this function to work with computeds. * @since 0.0.1 * @category Utility */ export function unwrap<T> ( wrapped: MaybeWrapped<T> ): T; export function unwrap <T> ( wrapped: MaybeWrapped<T> ) { return wrapped instanceof Function ? wrapped() : isRef(wrapped) ? wrapped.value : wrapped; }