Skip to content
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

Add key argument to serialize and unserialize invocations #3

Merged
merged 2 commits into from
Oct 5, 2021

Conversation

MatiasArriola
Copy link
Contributor

Hello,

First of all, thanks for writing this library!

I came here looking for a redux-persist replacement after hitting some critical unresolved issues in my react-native apps. I'm relieved the move to redux-remember was relatively easy.

The only thing I was missing is some way to omit certain keys per reducer. I figured out I could do that by passing a custom serialize. But there was no way I could tell which slice I'm serializing from inside the serializer, hence this patch.

Here some code that illustrates this use-case:

const serializationOmissions = {
  auth: ['forgotPasswordCode'],
  home: ['loading'],
};

const serialize = (data: object, key = '') => {
  const result = omit(data, serializationOmissions[key]);
  return JSON.stringify(result);
};

const enhancer = rememberEnhancer(
      someStorage,
      ['auth', 'home', 'anyOtherSlice'],
      { serialize }
),

Just wanted to contribute back the changes I needed for my projects, hope you find it valuable.

Cheers!

@zewish
Copy link
Owner

zewish commented Oct 5, 2021

Hey @MatiasArriola.
Thanks for the PR and sorry for answering so late, but I've been quite busy lately.
At first glance seems a reasonable proposal. I'll have a look and get this merged and released today :)

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1270378095

  • 3 of 3 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1087060535: 0.0%
Covered Lines: 64
Relevant Lines: 64

💛 - Coveralls

@zewish zewish merged commit 505c0b3 into zewish:master Oct 5, 2021
@zewish
Copy link
Owner

zewish commented Oct 5, 2021

@MatiasArriola, I made the extra key parameter in the serialize and unserialize functions required, this way we can guarantee that your serialize/unserialize function always has a proper key to check against.

The latest version 3.0.1 is now released on npm, this version includes the extra key parameter you needed.

@zewish zewish added this to the 3.0.1 milestone Oct 5, 2021
@zewish zewish added the enhancement New feature or request label Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants