react-boilerplate icon indicating copy to clipboard operation
react-boilerplate copied to clipboard

Integrating redux-simple-router

Open mxstbr opened this issue 11 years ago • 7 comments

https://github.com/jlongster/redux-simple-router

mxstbr avatar Nov 25 '15 19:11 mxstbr

Although I find redux-simple-router to be very elegant - I dislike the fact that it prevents you from using immutablejs Map as your state. That's because of this line: https://github.com/rackt/redux-simple-router/blob/master/src/index.js#L43

Once you let libraries like redux-(simple-)router manipulate your state you have to make your state a simple JS object. If you choose to use Immutablejs for the benefits of strict immutability - you need to wrap it with an object - and it's truly annoying.

zavelevsky avatar Dec 27 '15 10:12 zavelevsky

I'm not currently using Immutable JS because I'm not sure why I should include it. What are the benefits?

mxstbr avatar Dec 27 '15 10:12 mxstbr

I wanted a way to prevent state manipulation - and the subtle bugs that follow. For example - if during shouldComponentUpdate you compare your previous state to the new state - you'll always get equality because it's the same instance. This sort of "defensive" design is sometimes necessary when working with a team.

Also, using an API such as ImmutableJS' makes you stop and think of things like 1. where do you perform the state manipulation (you don't want to start importing immutablejs everywhere) and 2. what's the cost of the manipulation (copying huge collections much?).

Lastly - some strong functionality out of the box (things you'll usually use lodash for).

I'm not saying you should use ImmutalbeJS - but take into account that enough projects use it for it to be a consideration.

zavelevsky avatar Dec 27 '15 10:12 zavelevsky

I see what you mean. And how does the Object.assign in redux-simple-router interfere with that?

mxstbr avatar Dec 27 '15 10:12 mxstbr

Short answer: Object.assign returns an object - not an Immutable.Map. So you have a Map as your state and after their reducer is called you suddenly have a simple object.

The idea behind redux-simple-router (and also redux-router) is to take your state object and add their own subtree for routing state. But they assume your root state instance is of an object type. They can simply change it by allowing you to provide a custom reducer - and I opened a bug.

zavelevsky avatar Dec 27 '15 10:12 zavelevsky

Ah I see, thanks very much for the info, I didn't consider that at all!

I won't be including redux-simple-router then, lets revisit this when https://github.com/rackt/redux-simple-router/issues/140 is added!

mxstbr avatar Dec 27 '15 12:12 mxstbr

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar May 30 '18 18:05 lock[bot]