-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible not to persist data to storage if it's undefined ? #513
Comments
Hi @VasRoko! The code using apollo-cache-persist/src/Persistor.ts Lines 41 to 75 in cbf1b19
As you can see, it's called with whatever the cache content is, and the returned value gets persisted. If you return undefined, the undefined gets persisted. Maybe following this test case: apollo-cache-persist/src/__tests__/persistCache.ts Lines 177 to 182 in cbf1b19
You could return something as a initial state instead of undefined? Also, I'd suggest taking a break (I'd need one too 😅). From the looks of it, you're juggling with caches on several layers (in-memory & persisted) which will be difficult to keep in sync. |
Thanks for your explanation @wodCZ ! I can see in the code, that It seems that having initial state instead of
Not sure I would agree, mutating apollo cache, has in some sense functioned as a state management system and works perfectly fine in our use case. |
There's https://github.com/TallerWebSolutions/apollo-cache-instorage, a result of discussion in #2 (comment).
Yeah, I've been there. I didn't mean to attack your decision, my suggestion was purely a friendly advice. I guess I'm biased against storing an app state next to a http layer. |
that looks interesting, thanks for the suggestion! I'll check it out.
Any advice is always welcomed, I am open minded and willing to hear suggestions for improvement. Thanks again @wodCZ ! You've been a great help, really appreciate it. Feel free to close this thread. |
I need a bit of help; I'm not sure if it's intended behavior or a bug where empty data in persistenceMapper function is stored in localStorage as
undefined
which results in entire cache being cleared.Use case:
I have
cacheContents
, which are typically products fetched from the server and stored in the cache. Next, I would like to pull outtempContents
that are stored in localStorage, combine them withcacheContents
, and store all in the Apollo cache. However, I want to keep onlytempContents
in localStorage notcacheContents
.It seems that this is possible to achieve with the usage of
persistenceMapper
where I can define what I want to store in my localStorage. This works as expected when some data is already in localStorage; however, the issue arises when the user loads the page for the first time, andtempContents
do not exist. Therefore, filtered data is set to undefined. The problem with undefined it completely wipes out everything in my cache, so the page is empty.Code Example
Is there a way solve this?
The text was updated successfully, but these errors were encountered: