@gang-js/core
Version:
a state sharing algorithm
18 lines (17 loc) • 496 B
JavaScript
/** create a store from localStorage/sessionStoreage signature */
export function createGangStore(context) {
return {
get(key) {
const data = context.getItem(key);
if (data == null)
return null;
return JSON.parse(data);
},
set(key, value) {
if (value === undefined)
context.removeItem(key);
else
context.setItem(key, JSON.stringify(value));
}
};
}