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

Keys with array values are transformed to objects #16

Closed
pianohacker opened this issue Oct 9, 2015 · 4 comments
Closed

Keys with array values are transformed to objects #16

pianohacker opened this issue Oct 9, 2015 · 4 comments

Comments

@pianohacker
Copy link

Because typeof [] == 'object' in our favorite language, the reducer in autoRehydrate will activate the shallow merge behavior for arrays and turn them into objects. I'm currently working around this with a custom autoRehydrate, but it would be nice if this were handled better.

Open question: should arrays be shallow-merged, or slurped in without modification? I'd say the latter, both because it makes more sense for my application and because I don't think arrays can be sanely merged.

@rt2zz
Copy link
Owner

rt2zz commented Oct 9, 2015

Good catch. I agree, if the sub state is an array lets just take it as is.

I think this can be easily done with a bit of conditional Array.isArray around https://github.com/rt2zz/redux-persist/blob/master/src/autoRehydrate.js#L45

Let me know if you get it working. I have been meaning to do a bit of cleanup and code beautification in autoRehydrate anyway..

@rt2zz
Copy link
Owner

rt2zz commented Oct 10, 2015

I just pushed an update that fixes this issue. Will release a new version soon.

@rt2zz rt2zz closed this as completed Oct 10, 2015
@rt2zz
Copy link
Owner

rt2zz commented Oct 10, 2015

thanks for pointing this out!

@pianohacker
Copy link
Author

Wow. Fantastic! I already loved this module except for this niggling edge case (as it exactly matched what I was doing but was much cleaner), and this was a super fast response. Thanks!

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

No branches or pull requests

2 participants