@reffect/localstore
Version:
localStorage middleware for Reffect
3 lines (2 loc) • 543 B
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@reffect/core");exports.localstore=(t,o)=>{const r=e.manage(t);if("unknown"===r.name)throw"store should have unique name to use localstore middleware";const a=`@reffect/store/${r.name}`,s=localStorage.getItem(a);if(null!==s){const e=JSON.parse(s);r.initialState=o(e),Object.assign(t,o(e))}let l=null;return r.subscribe((e,t,o)=>{clearTimeout(l),l=setTimeout(()=>{localStorage.setItem(a,JSON.stringify({...o}))},144)}),t};
//# sourceMappingURL=reffect-localstore.cjs.js.map