Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

the bug of filter #240

Open
my3188 opened this issue Jan 26, 2020 · 12 comments
Open

the bug of filter #240

my3188 opened this issue Jan 26, 2020 · 12 comments

Comments

@my3188
Copy link

my3188 commented Jan 26, 2020

  • vuex-persistedstate version:2.7.0
  • node version:12.14.0
  • npm (or yarn) version:6.13.4

Relevant code or config

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
  modules,
  plugins: [
    createPersistedState({
      storage: window.sessionStorage,
      filter: mutation => {
        let rs = mutation.type != "UPDATE_NAME";
        return rs;
      },
      
    })
  ],
});

What you did:
I want all state to be persistent, except for state.name, The Mutations of state.name is “UPDATE_NAME”.
What happened:
I find state.name is persistent

Reproduction sandbox:

Problem description:

Suggested solution:

@my3188
Copy link
Author

my3188 commented Jan 27, 2020

reducer 和 filter都存在bug,我已经在开发中测试证明存在bug
paths是可以使用的,但是它只支持类似白名单的功能,不支持类似黑名单的功能,所以使用起来在某些场景下会麻烦

@robinvdvleuten
Copy link
Owner

I am missing a codesandbox here so I can reproduce it out myself. Could you try to filter out the state.name through the paths option?

@robinvdvleuten
Copy link
Owner

Or is that what you've tried to say in your comment? I cannot read any Asian characters.

@my3188
Copy link
Author

my3188 commented Mar 3, 2020

Or is that what you've tried to say in your comment? I cannot read any Asian characters.

There are bugs in both reducer and filter. I have tested and proved that there are bugs in development.Paths can be used correctly, but it only supports functions similar to white list, and does not support functions similar to black list, so it will be troublesome in some scenarios.
Like the above example, I may have 100 states, I hope 99 states are persistent, only one is not persistent, and using paths is very inconvenient

@my3188
Copy link
Author

my3188 commented Mar 3, 2020

I am missing a codesandbox here so I can reproduce it out myself. Could you try to filter out the state.name through the paths option?

paths is ok.but paths is Inconvenient in my scene.

@moltar
Copy link

moltar commented May 12, 2020

I'm seeing this bug too. filter has no effect.

@TheFrogDaddy
Copy link

I too have this same issue, filter fires but has no effect.

@mozart77
Copy link

mozart77 commented Jul 9, 2020

Same story

@iqbaladinur
Copy link

same here, i have tried reduce and filter. no one work.

@robinvdvleuten
Copy link
Owner

Can someone who has issues with this create a reproducible sandbox please?

@myzkyy
Copy link

myzkyy commented Jan 12, 2021

I noticed that returning false in filter function prevent from running persist at that time, but the state is eventually persisted when the other mutation is called.

Sample code:
https://codesandbox.io/s/vuex-persistedstate-filter-sample-iwt6t

@robinchow
Copy link

Looking at the implementation a bit more - filter is working as intended. It only filters mutations that triggers saving the vuex state - it's not intended to define which parts of the state is saved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants