vue-hooks-plus
Version:
Vue hooks library
28 lines (27 loc) • 706 B
JavaScript
const vue = require("vue");
function useMap(initialValue) {
const getInitValue = () => {
return initialValue ? new Map(initialValue) : /* @__PURE__ */ new Map();
};
const state = vue.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, vue.markRaw(actions)];
}
module.exports = useMap;
;