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.

Opposite of reducer functionality

See original GitHub issue

Hello,

The reducer property is useful for defining all the keys you want to persist. I am looking for a functionality that does the opposite: where I can define a set of keys that I don’t want persisted.

Is it currently possible to achieve this? If so, how?

My suggestion would be an exclude array with a set of keys, e.g: ... exclude: ['user.password', 'user.email'] ...

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
habaneroofdoomcommented, Apr 3, 2020

You can use the spread operator to achieve this neatly. Assume your state has a property “password” you want to exclude, this works quite nicely for me:

reducer: (state) => {
    const { password, ...others } = state;
    return others;
  },
4reactions
Nolencecommented, Mar 14, 2019

redux-persist has the idea of whitelisting and blacklisting parts of state which I found really useful while I was working with that library. I don’t think it would be out of place to add something like that here.

Anyways, here’s what I did to possibly save someone some time:

const vuexLocal = new VuexPersistence({
  storage: window.localStorage,
  reducer: state =>
    Object.keys(state).reduce((acc, curr) => {
      if (!["user", /* ... */].includes(curr)) acc[curr] = state[curr];
      return acc;
    }, {})
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the opposite of reducer? - WordHippo
The word reducer often refers to a pipe component that connects larger diameter pipes to smaller ones. It may also refer to a...
Read more >
Opposite of Array.reduce() in javascript - Stack Overflow
Since we're looking for a concise way to generate a given number of elements as an array, this "unfold" function does it with...
Read more >
Eccentric reducer - Wikipedia
An eccentric reducer is a fitting used in piping systems between two pipes of different diameters. The same fitting can be used in...
Read more >
Another word for REDUCER > Synonyms & Antonyms
noun. a substance capable of bringing about the reduction of another substance as it itself is oxidized; used in photography to lessen the...
Read more >
Reducer antonyms - 34 Opposites of Reducer
Antonyms for Reducer · expander · extender · amplifier · enlarger · gainer · increaser · intensifier · raiser.
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