UNPKG

vue-hooks-plus

Version:
29 lines (28 loc) 699 B
import { ref, markRaw } from "vue"; function useMap(initialValue) { const getInitValue = () => { return initialValue ? new Map(initialValue) : /* @__PURE__ */ new Map(); }; const state = ref(getInitValue()); const actions = { set: (key, value) => { state.value.set(key, value); }, get: (key) => { return state.value.get(key); }, remove: (key) => { state.value.delete(key); }, has: (key) => state.value.has(key), clear: () => state.value.clear(), setAll: (newMap) => { state.value = new Map(newMap); }, reset: () => state.value = getInitValue() }; return [state, markRaw(actions)]; } export { useMap as default };