This commit is contained in:
2025-07-23 16:57:31 +03:30
parent 96b0d450b6
commit ffe1d06893
4701 changed files with 449700 additions and 367 deletions
@@ -0,0 +1,38 @@
import { ref, unref, watchEffect, watch, toRaw } from 'vue';
function useMergedState(defaultStateValue, option) {
const {
defaultValue,
value = ref()
} = option || {};
let initValue = typeof defaultStateValue === "function" ? defaultStateValue() : defaultStateValue;
if (value.value !== void 0) {
initValue = unref(value);
}
if (defaultValue !== void 0) {
initValue = typeof defaultValue === "function" ? defaultValue() : defaultValue;
}
const innerValue = ref(initValue);
const mergedValue = ref(initValue);
watchEffect(() => {
let val = value.value !== void 0 ? value.value : innerValue.value;
if (option.postState) {
val = option.postState(val);
}
mergedValue.value = val;
});
function triggerChange(newValue) {
const preVal = mergedValue.value;
innerValue.value = newValue;
if (toRaw(mergedValue.value) !== newValue && option.onChange) {
option.onChange(newValue, preVal);
}
}
watch(value, () => {
innerValue.value = value.value;
});
return [mergedValue, triggerChange];
}
export { useMergedState as u };
//# sourceMappingURL=useMergedState-BZEfJ8Fl.mjs.map