Replies: 1 comment 5 replies
-
Custom |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, this perhaps might not be such a great idea, so I'm open to discussion about how its not feasible, or doesn't make sense.
Question:
Why are we serializing/deserializing and writing the entire state object from a store when we persist as opposed to saving them individually to separate key-value records in the storage?
I understand it is far less complex to just simply serialize the entire state (+ version) and throw that into localStorage. However, I have adopted using IndexedDB with a custom storage (a version where i don't serialize or deserialize, but rather filter out any functions from the state and then save the entire state to IndexedDB.
However, I am using this in a situation where I will have multiple writes of data per second for an increasingly large data set (think procedural generation of a tile map in a game with a game store). Putting aside that I could optimize so that it doesn't write multiple times a second... In my mind, I would really like to have each state property be its own IndexedDB key-value record.
This would enable me to only write updates that pertain to the tile map, instead of the entire state object for that store. Now I understand I probably should have a separation of concerns and move the map stuff to its own store (and now that I think about it, that's not a terrible idea). However, this question still somewhat applies as even then I would have to put just the tilemap in its own store in order to only write to that item when it gets updated.
I haven't done any benchmarking on my custom storage solution, so what I'm doing might be pretty slow and I may just opt for saving the specific state items to the IndexedDB in a set item in an action just for those ones and persist the rest.. 🤷♂️
Also, if I were to use the slices pattern where I add it all to one global store, this seems the like problem would compound (I haven't actually tested that yet) since you are now persisting everything together.
Thoughts? (and sorry for the ramble)
Beta Was this translation helpful? Give feedback.
All reactions