[Feature] persist results from find, get service methods in store
See original GitHub issueIt would be useful if the results of service get
or find
methods were also stored in store.records
. Currently, they are cached in the queryResult
key.
In my app, when server side rendering, I populate store.records
with the relevant results for a given route (say the homepage - /
).
If the user doesn’t begin their browsing on that page, the server-provided store won’t have records. When the user eventually navigates to /
, I want to initiate the call to get the records in my componentDidMount
hook in React. But then the results aren’t store.records
.
I could merge the data from queryResults
and store.records
(throwing away any duplicates). At best, that’s a hacky fix because the next query I perform will clear the previous data in queryResults
– and suppose the next query is a subset of the current results, then I’m throwing away data.
It would be preferable to have a single source of truth for all data for any particular service. Any time I call get
or find
, the data is persisted in store.records
. It’s different from the current behavior – store.records
stores records received from realtime events only.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
I’ve read your issue several times and I wrote a long reply but the short of it is this.
store.records
is intended for replication engines which replicate part of a file. Only they know the selection criteria, so Feathers calls cannot be merged intostore.records
.You seem to be using
store.records
as a cache. You are not taking mutations by others into account because I think you are using it only server side.The approach I suggest is to implement a cache with a reducer which acts on the repo’s _FULFILLED action code for the service. It can either use
store.records
or extend the repo’s store. You could use the STORE action code to clearstore.records
.I think we can close this. Feel free to reopen it.