You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note how setting/toggling to undefined does not work.
I basically take the info about the store contract and the update that's missing there to create a wrapper around a writable store, in this case a persistent one. update is basically copied from this repo; not sure if there's a better way to implement it - note what the Svelte docs say about get.
Edit: This should also be possible using svelte-writable-derived. I haven't tried it and the examples sadly don't show it, but the docs indicate it should work.
Original example:
varjsonStore=writable(`{"I'm a property": true}`);varobjectStore=writableDerived(jsonStore,(json)=>JSON.parse(json),(object)=>JSON.stringify(object));
What should work for you:
varjsonStore=writable(`{"I'm a property": true}`);varobjectStore=writableDerived(jsonStore,(json)=>JSON.parse(json),(object,set)=>{if(object!==undefined)set(JSON.stringify(object));},);
I'd like to save data in local storage unless that data is NaN or undefined. Is there a way to do that?
I realise this might be a Svelte rather than a svelte-persistent-store question
The text was updated successfully, but these errors were encountered: