@aplus-frontend/ui
Version:
36 lines (35 loc) • 968 B
JavaScript
import { ref as h, computed as w, watchEffect as I, unref as c, watch as S } from "vue";
import { INTERNAL_FORM_INSTANCE_MARK as N } from "../constant.mjs";
import { useInjectForm as M } from "../context.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 } = M(), i = V?.initialValue || e?.initialValue || void 0, u = h(i);
let n = o(i);
const f = w(() => (e && "value" in e ? e : void 0)?.value?.getInternalInstance(N) || d);
return I((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);
}), S(
() => 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
};