baseframe-js
Version:
A suite of useful Javascript plugins and functions to help with Front-end Development on websites
23 lines (22 loc) • 605 B
JavaScript
const storeMap = new WeakMap();
const Store = (storeElem, key, value) => {
const storeRecord = storeMap.get(storeElem) || storeMap.set(storeElem, {});
const keyExists = Reflect.has(storeRecord, key);
if (keyExists) {
const valueIsNull = value === null;
if (valueIsNull) {
delete storeRecord[key];
return null;
}
if (value) {
storeRecord[key] = value;
}
}
else {
if (value && value !== null) {
storeRecord[key] = value;
}
}
return storeRecord[key];
};
export default Store;