Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Make redux drive history? #138

Closed
Closed
@naw

Description

@naw

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:

  1. Let the browser history tell redux what to do (e.g. back, forward, initial page load, etc.)
  2. Let links, buttons, etc. tell redux what to do (i.e. not tell the router what to do).
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions