It might be a really stupid idea.
But thinking more functionally, we always take a model and return a new model,
Could we somehow take the whole localState object and produce a new localState object ?
Browser.Storage.getLocalStorage or Browser.Storage.getSessionStorage
Read storage once, manipulate it like a normal model in Elm during the app’s lifetime, and then overwrite the whole thing every time you need to persist it.
If there comes a time during the app’s life, where you want to persist storage, you have a Cmd with Browser.Storage.persistLocalStorage and hands it (Dict String String) from your model.
In most cases, you only need to store before refresh and before page close ?
Subscriptions model =
update … … =
( model, persistStorage model.storage )
Evan has a good write up of the issues that need to be addressed before an Elm package for LocalStorage makes sense.
You can already write
persistLocalStorage in a quite straight forward way as ports on your own.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.