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

Using with Immutable.js #22

Closed
csillag opened this issue Jan 10, 2017 · 9 comments
Closed

Using with Immutable.js #22

csillag opened this issue Jan 10, 2017 · 9 comments

Comments

@csillag
Copy link

csillag commented Jan 10, 2017

Does this library support using Immutable.js with Redux?
If not, it would be nice to add it.

@supasate
Copy link
Owner

I never try with Immutable.js yet. Is there anything that can affect the result?

@ecozoic
Copy link

ecozoic commented Jan 23, 2017

I was playing around with Immutable.js this weekend so I decided to give this a try.

You can see an example of how this would work w/ Immutable in my fork: https://github.com/ecozoic/connected-react-router/pull/1/files

These changes assume your entire state object is an Immutable iterable (so if you use combineReducers that means you are using a library like redux-immutable). I've seen examples where the state object itself is mutable but all of its top level properties are immutable iterables. Implementation for something like that would be slightly different.

This is just a POC, to do something for real we would want this to be configurable somehow. Primary changes are in the ConnectedRouter where we read values from the store and in the connectRouter/routerReducer where we actually update state. Could maybe provide an "immutable" option on the router/middleware or more generally allow consumers to pass in some functions as props/arguments to customize behavior.

@supasate
Copy link
Owner

Thanks @ecozoic. I understand it now. I may provide useImmutable option to make it simple to use. (If you would like to submit a PR, it is welcome!)

I'm not sure how often people use other ways to select value from the state object. So, I may provide an option to specify selector function in the future if there are several requests on this feature.

@nickwaelkens
Copy link

I had made my own fork of this project supporting ImmutableJS, but it would be kind of stupid to make a separate PR when @ecozoic works wonders already! Great work.

I was wondering what the best API would be if you would support Immutable out of the box? One example is redux-form, eg it has 2 ways to import things;

import { Field } from 'redux-form'
import { Field } from 'redux-form/immutable'

It uses a factory function to create the correct type. Maybe the same principle can be used here?

@supasate
Copy link
Owner

@nickwaelkens I like the way redux-form did. I might go that path.

@supasate
Copy link
Owner

supasate commented Feb 4, 2017

Hi all, I've made it support Immutable.js already in the 4.0.0-beta.3 release.

Just import ConnectedRouter, routerMiddleware and connectRouter from connected-react-router/immutable.

See more details here.

@nickwaelkens
Copy link

nickwaelkens commented Feb 4, 2017

Great work @supasate. Will try this out soon but looks good!

@supasate supasate closed this as completed Feb 6, 2017
@ecozoic
Copy link

ecozoic commented Feb 9, 2017

Yes thanks so much @supasate ! Adding this to my react-starter and it seems to be working great!

EDIT - here's a PR w/ changes to support it. super easy!
https://github.com/ecozoic/react-starter/pull/39/files

@supasate
Copy link
Owner

@ecozoic Cool! Great to know it works for you!

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

4 participants