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

Async transforms #360

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

CharlieHess
Copy link

This PR resolves #303 by adding support for async transforms, behind a configuration flag (default behavior is unchanged). Folks with a well-defined use case can opt into this behavior at their own risk.

@CharlieHess
Copy link
Author

In my case I wanted to store secrets securely (say, in the keychain) and have them excluded from the persisted shape. Then, on rehydrate, I wanted to read the secrets from the keychain and apply them to the state as if they were there all along.

@CharlieHess
Copy link
Author

@rt2zz any thoughts on this one?

@antondomratchev
Copy link

@rt2zz We have the exact same use case for this feature, this would be very nice to have in the package.

@rt2zz
Copy link
Owner

rt2zz commented Jul 27, 2017

@CharlieHess sorry for the delay on getting back here. I like the implementation but am concerned by the raw amount of code, and also the possible support burden. I have been working on redux-persist v5 lately and there might be an opportunity to make some more drastic changes there.

Some options

  1. support async transforms out of the box, change the time iterator to no longer use setInterval and instead wait for the result of each transform before continuing to the next piece of state (potentially with a setTimeout in between)
  2. in v5 while we serialize in chunks, we aggregate the results and only write to disk once. With this, instead of trying to do async at the transform level, we could consider a new hook to pre/post process the aggregated state just before writing to disk and just after reading from disk.

Of course the challenge with option 2 is the variations are endless: some use cases might prefer to process the state before serialization, and other after. Some might require that the async process is blocking while others can run in parallel.

Since this current solution is working for you I encourage you to keep using it for the time being (redux-persist@4 is not going to change much at all, so keeping up to date should not be difficult) while we take more time to think through how the api should work in v5.

@mnquintana
Copy link

@rt2zz 👋 Just checking in - now that v5's out, what do you think would be the best approach for supporting async transforms now?

@sebastian-schlecht
Copy link

any progress on this?

@n-sviridenko
Copy link

Any news on this? We want to use it this way: maxdeviant/redux-persist-transform-encrypt#33

@pitops
Copy link

pitops commented Feb 28, 2019

Guys I really need this, any progress on merging?

@CharlieHess
Copy link
Author

We haven't needed to update to v5 yet and thus our fork (based off this branch) is still serving us for the time being. I won't be able to get back to this anytime soon but I bet Zack would consider a pull request!

@pirtlj
Copy link

pirtlj commented Aug 3, 2020

@rt2zz any progress here? I would love to see this supported.

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

Successfully merging this pull request may close these issues.

Is it possible to create an async transform?
9 participants