Make redux drive history? #138
Description
The idea behind redux-simple-router
is to keep history in sync between redux and the router history.
In my opinion, it's preferable for redux to be the source of truth for the router, rather than history to be the source of truth that is shared by the router and redux.
My idea is this:
- Let the browser history tell redux what to do (e.g. back, forward, initial page load, etc.)
- Let links, buttons, etc. tell redux what to do (i.e. not tell the router what to do).
- Finally, let redux tell the router what to do.
I have a basic draft of this here:
naw@5d6c893 (update: newer draft here: naw@a47914f)
The basic implementation is:
1 Give react-router a memoryHistory object instead of the real browserHistory object.
2. The only thing that writes to memoryHistory is a redux store subscriber.
3. wrap the memoryHistory object we give to react-router so that we can intercept push
calls so that they call a changeLocation action creator rather than writing to memoryHistory directly.
4. Separately, listen to a real browserHistory object, and call the changeLocation action creator from the history listener.
Also, I'm using a slightly different approach for preventing cycles, so I believe the locationsAreEqual
complexity is unnecessary.
I've probably missed some edge cases (or perhaps I've missed something larger than that?), but I wanted to share the basic idea and get some feedback.