UNPKG

@aplus-frontend/ui

Version:

36 lines (35 loc) 968 B
import { useInjectForm as h } from "../context.mjs"; import { ref as w, computed as I, watchEffect as S, unref as c, watch as N } from "vue"; import { INTERNAL_FORM_INSTANCE_MARK as M } from "../constant.mjs"; import { getModelValue as v } from "../utils/get.mjs"; function o(t) { try { return JSON.stringify(t); } catch { return Math.random(); } } function _(t, e, V) { const { internalInstance: d, model: g } = h(), i = V?.initialValue || e?.initialValue || void 0, u = w(i); let n = o(i); const f = I(() => (e && "value" in e ? e : void 0)?.value?.getInternalInstance(M) || d); return S((a) => { if (!f.value) return; const r = f.value.registerWatch((l) => { const s = v(l, c(t)), m = o(s); m !== n && (u.value = s, n = m); }); a(r); }), N( () => c(t), (a) => { const r = v(c(g), a), l = o(r); l !== n && (u.value = r, n = l); } ), u; } export { _ as default, _ as useWatch };