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

Commit 53097f0

Browse files
committed
Merge pull request #93 from justingreenberg/update-readme
Update README and add CHANGELOG
2 parents 3545a3e + 00436af commit 53097f0

File tree

2 files changed

+92
-86
lines changed

2 files changed

+92
-86
lines changed

CHANGELOG

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [Unreleased]
6+
7+
* Update to the new history API (#89)
8+
9+
## [1.0.0] - 2015-12-07
10+
11+
### Breaking
12+
13+
* The `updatePath` action creator has been removed in favor of `pushPath` and `replacePath` (#38)
14+
* We have added support for routing state (#38)
15+
* Our actions are now [FSA compliant](https://github.com/acdlite/flux-standard-action) (#63)
16+
17+
### Other
18+
19+
* Redux DevTools should now work as expected (#73)
20+
* As we no longer depend on `window.location`, `<base href="...">` should now work (#62)
21+
* We've done lots of work on finding the right way to stop cycles, so hopefully we shouldn't have any unnecessary location or store updates (#50)

README.md

+71-86
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,60 @@
1-
21
# redux-simple-router
32

4-
[![npm version](https://img.shields.io/npm/v/redux-simple-router.svg?style=flat-square)](https://www.npmjs.com/package/redux-simple-router)
5-
[![npm downloads](https://img.shields.io/npm/dm/redux-simple-router.svg?style=flat-square)](https://www.npmjs.com/package/redux-simple-router)
3+
[![npm version](https://img.shields.io/npm/v/redux-simple-router.svg?style=flat-square)](https://www.npmjs.com/package/redux-simple-router) [![npm downloads](https://img.shields.io/npm/dm/redux-simple-router.svg?style=flat-square)](https://www.npmjs.com/package/redux-simple-router)
64

7-
*Let react-router do all the work.*
5+
**Let react-router do all the work** :sparkles:
86

9-
[Redux](https://github.com/rackt/redux) is cool.
10-
[react-router](https://github.com/rackt/react-router) is neat. The
11-
problem is that react-router manages an important piece
12-
of your application state: the URL. If you are using redux, you want
13-
your app state to fully represent your UI; if you snapshotted the app
14-
state, you should be able to load it up later and see the same thing.
7+
[Redux](https://github.com/rackt/redux) is awesome. [React Router](https://github.com/rackt/react-router) is cool. The problem is that react-router manages an important piece of your application state: the URL. If you are using redux, you want your app state to fully represent your UI; if you snapshotted the app state, you should be able to load it up later and see the same thing.
158

16-
react-router automatically maps the current URL to a path down your
17-
component tree, and continually does so with any URL changes. This is
18-
very useful, but we really want to store this state in redux as well.
9+
react-router does a great job of mapping the current URL to a component tree, and continually does so with any URL changes. This is very useful, but we really want to store this state in redux as well.
1910

20-
The entire state that we are interested in boils down to one thing:
21-
the URL. This is an extremely simple library that just puts the URL in
22-
redux state and keeps it in sync with any react-router changes.
23-
Additionally, you can change the URL via redux and react-router will
24-
change accordingly.
11+
The entire state that we are interested in boils down to one thing: the URL. This is an extremely simple library that just puts the URL in redux state and keeps it in sync with any react-router changes. Additionally, you can change the URL via redux and react-router will change accordingly.
2512

26-
```js
27-
npm install redux-simple-router
28-
```
13+
##### _What about redux-router?_
14+
15+
[redux-router](https://github.com/rackt/redux-router) is another project which solves the same problem. However, it's far more complex. Take a quick look at [the code for this library](https://github.com/jlongster/redux-simple-router/blob/master/src/index.js)—it's extremely minimal. redux-router is much bigger and more complex.
2916

30-
## Isn't there already redux-router?
17+
That said, redux-router is a fine project and has features this doesn't provide. Use it if you like it better.
3118

32-
[redux-router](https://github.com/rackt/redux-router) is another
33-
project which solves the same problem. However, it's far more complex.
34-
Just look at this code: the whole thing is only 68 lines of JS.
35-
redux-router is much bigger and more complex.
19+
**Compared with redux-router:**
3620

37-
That said, redux-router is a fine project and has features this
38-
doesn't provide. Use it if you like it better.
21+
* Much smaller and simpler. You don't need to learn another library on top of everything else.
22+
* We encourage direct access of react-router APIs. Need server-side rendering, or something else advanced? Just read react-router's docs.
23+
* We only store current URL and state, whereas redux-router stores the entire location object from react-router.
3924

40-
The differences between this and redux-router:
25+
## Documentation
4126

42-
* Much smaller and simpler. You don't need to learn another library on
43-
top of everything else.
44-
* We encourage direct access of react-router APIs. Need server-side
45-
rendering, or something else advanced? Just read react-router's
46-
docs.
47-
* The piece of state is just a URL string, whereas redux-router stores
48-
the full location object from react-router.
27+
0. [Usage](#how-to-use)
28+
- [Installation](#installation)
29+
0. [Tutorial](#tutorial)
30+
0. [Examples](#examples)
31+
0. [API](#api)
32+
- [`syncReduxAndRouter(history, store, selectRouterState?)`](#syncreduxandrouter)
33+
- [`routeReducer`](#routereducer)
34+
- [`UPDATE_PATH`](#update-path)
35+
- [`pushPath(path, state, { avoidRouterUpdate = false } = {})`](#pushpath)
36+
- [`replacePath(path, state, { avoidRouterUpdate = false } = {})`](#replacepath)
37+
0. [See also](#see-also)
4938

50-
This only depends on the `history.listen` function from react-router
51-
and the `store.getState` and `store.subscribe` functions from redux.
52-
It should be very future-proof with any versions of either libraries.
39+
### Usage
5340

54-
## Examples
41+
The idea of this library is to use react-router's functionality exactly like its documentation tells you to. You can access all of its APIs in routing components. Additionally, you can use redux like you normally would, with a single app state and "connected" components. It's even possible for a single component to be both if needed.
5542

56-
There are examples in the `examples` directory:
43+
[redux](https://github.com/rackt/redux) (`store.routing`) &nbsp;&harr;&nbsp; [**redux-simple-router**](https://github.com/jlongster/redux-simple-router) &nbsp;&harr;&nbsp; [history](https://github.com/rackt/history) (`history.location`) &nbsp;&harr;&nbsp; [react-router](https://github.com/rackt/react-router)
5744

58-
1. [basic](https://github.com/jlongster/redux-simple-router/blob/master/examples/basic)
45+
We only store current URL and state, whereas redux-router stores the entire location object from react-router. You can read it, and also change it with an action.
5946

60-
## How to Use
47+
#### Installation
6148

62-
The idea of this library is to use react-router's functionality exactly
63-
like its documentation tells you to. You can access all of its APIs in
64-
routing components. Additionally, you can use redux like you normally
65-
would, with a single app state and "connected" components. It's even
66-
possible for a single component to be both if needed.
49+
The latest redux-simple-router package can be install via NPM:
6750

68-
This library provides a single point of synchronization: the
69-
`routing.path` piece of state which is the current URL. You can read
70-
it, and also change it with an action.
51+
```js
52+
npm install --save redux-simple-router
53+
```
7154

72-
Here's some code:
55+
### Tutorial
56+
57+
Let's take a look at a simple example.
7358

7459
```js
7560
import React from 'react'
@@ -102,22 +87,17 @@ ReactDOM.render(
10287
)
10388
```
10489

105-
Now you can read from `state.routing.path` to get the URL. It's far
106-
more likely that you want to change the URL more often, however. You
107-
can use the `updatePath` action creator that we provide:
90+
Now you can read from `state.routing.path` to get the URL. It's far more likely that you want to change the URL more often, however. You can use the `pushPath` action creator that we provide:
10891

10992
```js
110-
import { updatePath } from 'redux-simple-router'
93+
import { pushPath } from 'redux-simple-router'
11194

11295
function MyComponent({ dispatch }) {
113-
return <Button onClick={() => dispatch(updatePath('/foo'))}/>;
96+
return <Button onClick={() => dispatch(pushPath('/foo'))}/>;
11497
}
11598
```
11699

117-
This will change the state, which will trigger a change in react-router.
118-
119-
Additionally, if you want to respond to the path update action, just
120-
handle the `UPDATE_PATH` constant that we provide:
100+
This will change the state, which will trigger a change in react-router. Additionally, if you want to respond to the path update action, just handle the `UPDATE_PATH` constant that we provide:
121101

122102
```js
123103
import { UPDATE_PATH } from 'redux-simple-router'
@@ -130,39 +110,44 @@ function update(state, action) {
130110
}
131111
```
132112

133-
For more context, check out this [full example](https://github.com/freeqaz/redux-simple-router-example).
113+
### Examples
114+
115+
* [examples/basic](https://github.com/jlongster/redux-simple-router/blob/master/examples/basic) - basic reference implementation
116+
117+
Examples from the community:
118+
119+
* [davezuko/react-redux-starter-kit](https://github.com/davezuko/react-redux-starter-kit) - popular redux starter kit
120+
* **tip**: migrating from redux-router? use [this commit](https://github.com/davezuko/react-redux-starter-kit/commit/db66626ca8a02ecf030a3f7f5a669ac338fd5897) as a reference
121+
* [freeqaz/redux-simple-router-example](https://github.com/freeqaz/redux-simple-router-example) - example implementation
122+
123+
_Have an example to add? Send us a PR!_
124+
125+
### API
126+
127+
#### `syncReduxAndRouter(history, store, selectRouterState?)`
128+
129+
Call this with a react-router and a redux store instance to install hooks that always keep both of them in sync. When one changes, so will the other.
130+
131+
Supply an optional function `selectRouterState` to customize where to find the router state on your app state. It defaults to `state => state.routing`, so you would install the reducer under the name "routing". Feel free to change this to whatever you like.
134132

135-
## API
133+
#### `routeReducer`
136134

137-
### `syncReduxAndRouter(history, store, selectRouterState?)`
135+
A reducer function that keeps track of the router state. You must to add this reducer to your app reducers when creating the store. If you do not provide a custom `selectRouterState` function, the piece of state must be named `routing`.
138136

139-
Call this with a react-router and a redux store instance to install
140-
hooks that always keep both of them in sync. When one changes, so will
141-
the other.
137+
#### `UPDATE_PATH`
142138

143-
Supply an optional function `selectRouterState` to customize where to
144-
find the router state on your app state. It defaults to `state =>
145-
state.routing`, so you would install the reducer under the name
146-
"routing". Feel free to change this to whatever you like.
139+
An action type that you can listen for in your reducers to be notified of route updates.
147140

148-
### `routeReducer`
141+
#### `pushPath(path, state, { avoidRouterUpdate = false } = {})`
149142

150-
A reducer function that keeps track of the router state. You need to
151-
add this reducer to your app reducers when creating the store. **The
152-
piece of state must be named `routing`** (unless you provide a custom
153-
`selectRouterState` function).
143+
An action creator that you can use to update the current URL and update the browser history. Just pass it a string like `/foo/bar?param=5` as the `path` argument.
154144

155-
### `UPDATE_PATH`
145+
You can optionally pass a state to this action creator to update the state of the current route.
156146

157-
An action type that you can listen for in your reducers.
147+
The `avoidRouterUpdate`, if `true`, will stop react-router from reacting to this URL change. This is useful if replaying snapshots while using the `forceRefresh` option of the browser history which forces full reloads. It's a rare edge case.
158148

159-
### `updatePath(path, noRouterUpdate)`
149+
#### `replacePath(path, state, { avoidRouterUpdate = false } = {})`
160150

161-
An action creator that you can use to update the current URL. Just
162-
pass it a string like `/foo/bar?param=5`.
151+
An action creator that you can use to replace the current URL without updating the browser history.
163152

164-
The `noRouterUpdate`, if `true`, will stop react-router from reacting
165-
to this and all future URL changes. Pass `false` to make it start
166-
reacting again. This is useful if replaying snapshots while using the
167-
`forceRefresh` option of the browser history which forces full
168-
reloads. It's a rare edge case.
153+
The `state` and the `avoidRouterUpdate` parameters work just like `pushPath`.

0 commit comments

Comments
 (0)