UNPKG

@antdv/pro-utils

Version:

@antdv/pro-utils

22 lines (21 loc) 528 B
import { ref, watch } from "vue"; import { omit } from "../../omit/index.mjs"; function useMemo(factory, sources, opt) { const cacheRef = ref(factory()); watch( sources, (next, pre, onCleanup) => { if (opt == null ? void 0 : opt.shouldUpdate) { if (opt == null ? void 0 : opt.shouldUpdate(pre, next, onCleanup)) cacheRef.value = factory(); } else { cacheRef.value = factory(); } }, omit(opt || {}, ["shouldUpdate"]) ); return cacheRef; } export { useMemo };