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

Add option to include or exclude paths #4

Closed
syropian opened this issue Nov 28, 2016 · 6 comments
Closed

Add option to include or exclude paths #4

syropian opened this issue Nov 28, 2016 · 6 comments

Comments

@syropian
Copy link

Sometimes it's easier to exclude certain paths than to manually include a bunch. If you're busy I can take a crack at this and file a PR.

@robinvdvleuten
Copy link
Owner

Good suggestion @syropian! It's added in the v1.1.0 release. Please see the README for the reducer function.

@RashadSaleh
Copy link

@robinvdvleuten Hello! Thanks for the cool plugin. Can you please elaborate on how this can work? An example would be excellent.

@robinvdvleuten
Copy link
Owner

Hi @RashadSaleh! You can see how the functionality works by looking at the defaultReducer in plugin.js. It's in its base just a simple JS reducer which returns an object containing all values you want to store.

@Edujugon
Copy link

Edujugon commented May 3, 2017

@robinvdvleuten
Is this the best approach for reducer function?

reducer: (state,paths) => {
                let reducer = Object.assign({},state);
                delete reducer.dates; // state which I don't want to persist.

                return reducer;
            }

Thanks in advance.

@robinvdvleuten
Copy link
Owner

@Edujugon please checkout the default reducer method here. It should look something like this in (in your case);

reducer (state, paths) {
  // No need to use let as the reducer itself can be immutable which do not mean that the properties 
  are not mutable (https://ponyfoo.com/articles/var-let-const)
  const reducer = Object.assign({}, state);
  // state which you don't want to persist.
  delete reducer.dates;

  return reducer;
}

Much easier is it though to give an array of paths to persist as option (https://github.com/robinvdvleuten/vuex-persistedstate#createpersistedstateoptions)

@sedatsevgili
Copy link

Btw, if anyone uses vuex with namespaces and not to persist some key in any module, Object.assign is not enough. You have to deep clone your state.

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

No branches or pull requests

5 participants