Closed kasparsj closed 1 month ago
ah yes thanks for spotting that! one idea that might simplify the implementation: maybe it's possible to use a regular nanostores atom
and update a session storage field on change (using .listen). The default value can be the session storage field.
i meant this:
const initialActivePattern = sessionStorage.getItem('activePattern');
const $activePattern = atom('activePattern', initialActivePattern);
$activePattern.listen((value) => sessionStorage.setItem('activePattern', value));
does that make sense?
I see, my idea was to keep the api same as persistentAtom
and base the implementation on this :
https://github.com/nanostores/persistent/pull/30 (no idea why it wasn't merged)
I see, my idea was to keep the api same as persistentAtom and base the implementation on this : https://github.com/nanostores/persistent/pull/30 (no idea why it wasn't merged)
atom
is also a Store
type (WritableAtom
) which works for the part of the API that we use (set
, get
and passing it to useStore
) so I don't see why we need more complexity here
please check now...
sessionStorage !== undefined
check, to not error in env where it's not supported e.g. testing env etcnewValue === undefined
check, since it's what the atom docs say, how to deletethanks, this now looks good. In the future viewingPatternData
might be refactored a little bit to not need parsing on every render (PatternsTab > parseJSON), but I guess that can be done in a separate PR. Also I wonder if a browser that doesn't support sessionStorage can even run the rest of strudel :P
Is this ready to merge?
Is this ready to merge?
yup! thanks @kasparsj
localStorage, which is shared between tabs, was being used for these, and although it wasn't [live] synchronised between tabs, it would e.g. restore to the last saved data (accross all tabs) upon refresh/reload/new window.
sessionStorage is separate for each tab, but persists tab data across refreshes.
this should fix #1049 as it's tracking the data about which pattern is active/selected for each tab separately.