question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

filter is still saving the mutation to localforge

See original GitHub issue

Currently I have:

const ignoreMutations = [
  'currentUser/setAuthenticated',
  'currentUser/setLoggedIn',
  'resource/setTypes',
  'resource/setCurrentVideo',
]

const vuexPersist = new VuexPersist({
  asyncStorage: true,
  key: 'vuex',
  storage: localForage,
  filter: mutation => !ignoreMutations.includes(mutation.type),
}).plugin

When I check localforge the data has been saved, shouldn’t this not be the case?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
cjcommented, Jun 24, 2018

@championswimmer I see why it’s not working as I expected. https://github.com/championswimmer/vuex-persist/blob/master/src/index.ts#L169-L172 It’s saving the entire state regardless of what the mutation is. So lets say you have a state like:

export const state = () => ({
  authenticated: false,
  loggedIn: false,
  data: {},
})

and you have 3 mutations setAuthenticated, setLoggedIn and, setData; If I have the following config that I showed above:

const ignoreMutations = [
  'currentUser/setAuthenticated',
  'currentUser/setLoggedIn',
  'resource/setTypes',
  'resource/setCurrentVideo',
]

const vuexPersist = new VuexPersist({
  asyncStorage: true,
  key: 'vuex',
  storage: localForage,
  filter: mutation => !ignoreMutations.includes(mutation.type),
}).plugin

If the mutation setData gets called, it is still going to save the state for authenticated and loggedIn, as it’s saving the entire state. I think what it should do instead is just deep merge in the mutation data.

0reactions
my3188commented, Jan 26, 2020

@cj How did you finally solve this problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Vuex-persist doesn't store anything in localStorage?
As said in the guide. The only way to actually change state in a Vuex store is by committing a mutation.
Read more >
Persist Vuex State with vuex-persist - DigitalOcean
Save your Vuex state to localStorage, sessionStorage, cookies, and more with ... filter: mutation => (true) }) const store = new Vuex.
Read more >
PersistOptions | vuex-persist - championswimmer
Method to filter which mutations will trigger state saving Be default returns true for all mutations. Check mutations using mutation.type.
Read more >
vuex-persist - npm
Choose which mutations trigger store save, and which don't, using filter ... Denotes if the store uses Promises (like localforage) or not
Read more >
persistQueryClient | TanStack Query Docs
This is set of utilities for interacting with "persisters" which save your ... Your query/mutation are dehydrated and stored by the persister you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found