Closed adeelshahid closed 6 years ago
no this is not possible, unless you model each document as a separate reducer (but that has its own set of challenges). You might be able to toy with redux-persist's internals to get this functionality, but tbh I think this is a pretty specific use case and probably a custom solution.
One big question: during rehydration, how do you know which documents you want to restore?
@rt2zz we can have a reserved reducer with a prefix _, like _persist.
e.g. _docs: [documents ids] _docs:doc_id (contains the meta)
later on rehydrate we merge all _docs:parts into docs
This can be used for extensibility in any decent size application, which will have a similar model.
Edit woops answered on wrong issue, moved answer here: https://github.com/rt2zz/redux-persist/issues/589#issuecomment-348333268
@rt2zz Curious about this as well. To expand on @adeelshahid's example, let's say I have an application where users can create and edit documents. Some slice of my state looks like this:
{
docIds: ['a', 'b', 'c', ...],
docs: {
a: { title: 'Document A', text: 'Lorem ipsum ...' },
b: { title: 'Document B', text: 'Lorem ipsum ...' },
c: { title: 'Document C', text: 'Lorem ipsum ...' },
...
}
}
Let's say documents can get fairly large, and that there can be a lot of them. I wouldn't want the entire document state to be stored under one key. Rather, I'd likely want something like this:
Key | Value |
---|---|
doc_ids |
"['a', 'b', 'c', ...]" |
doc_a |
"{ 'title': 'Document A', 'text': 'Lorem ipsum ...' }" |
doc_b |
"{ 'title': 'Document B', 'text': 'Lorem ipsum ...' }" |
doc_c |
"{ 'title': 'Document C', 'text': 'Lorem ipsum ...' }" |
That way, editing one document doesn't result in the whole state getting stringified and persisted.
@adeelshahid Why the close? Were you able to find a suitable workaround?
@ethanroday no I had a server based solution to remove the complexity from the reducer. Now anything in the app that relates to preferences, progress etc. are synced from the server side.
for example,
documents reducer with a Map of documents (each key represents a document id)
Is it possible to make the configuration so that each document id is stored in a separate key inside the localStorage