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

Split history syncing from action creators #259

Merged
merged 38 commits into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7cdc72a
Extract the action creators and middleware.
timdorr Feb 5, 2016
2946938
Pull in @gaearon's history syncer.
timdorr Feb 5, 2016
21b511b
Go with Babel Stage 1 for export extensions.
timdorr Feb 5, 2016
fbe174f
Update the example against the new API.
timdorr Feb 5, 2016
88bc0de
Minor reorg. Split the reducer to its own file.
timdorr Feb 5, 2016
a2ec57b
Fix linting in example.
timdorr Feb 5, 2016
36845f5
Hollow out the old tests and fill in something basic.
timdorr Feb 5, 2016
10e34d2
Update build script for multi-file setup.
timdorr Feb 5, 2016
4c17b0e
Clean up some testing framework stuff.
timdorr Feb 5, 2016
c61c92c
Use spread instead Object.assign. Following #259
webmasterkai Feb 6, 2016
4afd74f
Confirm location change before listener invokation
webmasterkai Feb 6, 2016
fc12f70
Begin updating example in README. Re #259
webmasterkai Feb 6, 2016
1a8c800
README syncHistory becomes syncHistoryWithStore
webmasterkai Feb 6, 2016
08b3818
Merge pull request #262 from webmasterkai/synchronicity
timdorr Feb 6, 2016
379dc9c
Add back route action tests.
timdorr Feb 6, 2016
def06ff
Add reducer tests. Ensure actions are FSA.
timdorr Feb 6, 2016
2b177f5
Add middleware test. Reorg test suite.
timdorr Feb 6, 2016
2c88667
rename UPDATE_LOCATION to CALL_HISTORY_METHOD
webmasterkai Feb 6, 2016
a452791
Merge pull request #265 from webmasterkai/actionTypeAlt
timdorr Feb 6, 2016
cb9d6b6
Redone docs.
timdorr Feb 7, 2016
50faa62
Add a note warning about reading from store.
timdorr Feb 7, 2016
4308208
Add back some other relevant tests.
timdorr Feb 7, 2016
0b7b322
Add docs for syncHistoryWithStore's options.
timdorr Feb 8, 2016
9b2dc36
Don't leave test side effects with history singltons.
timdorr Feb 8, 2016
820f46e
4.0.0-beta.1
timdorr Feb 8, 2016
8ed23ca
Merge remote-tracking branch 'origin/master' into synchronicity
timdorr Feb 10, 2016
98ceca0
Merge remote-tracking branch 'origin/master' into synchronicity
timdorr Feb 12, 2016
f0e09db
docs(readme): add example migration from ^3.0.0
Feb 12, 2016
d54496c
Merge pull request #271 from davezuko/patch-2
timdorr Feb 12, 2016
d45f1c6
Update README.md
justin808 Feb 14, 2016
60fa049
Merge pull request #278 from justin808/patch-2
timdorr Feb 14, 2016
8bc27b9
Merge remote-tracking branch 'origin/master' into synchronicity
timdorr Feb 15, 2016
cdc941d
Switch to run example on webpack-dev-server.
timdorr Feb 15, 2016
31b3809
added example to readme
svrcekmichal Feb 15, 2016
d2e5173
Merge pull request #280 from svrcekmichal/synchronicity
timdorr Feb 15, 2016
67aefaa
Merge remote-tracking branch 'origin/master' into synchronicity
timdorr Feb 15, 2016
87402ea
Add a SSR example.
timdorr Feb 17, 2016
8d4750e
Merge remote-tracking branch 'origin/master' into synchronicity
timdorr Feb 17, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015", "stage-2"]
"presets": ["es2015", "stage-1"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lib
node_modules
coverage
*.log
173 changes: 89 additions & 84 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ This example also demonstrates integration with

1. Install dependencies with `npm install` in this directory (make sure it creates a local node_modules)
2. By default, it uses the local version from `src` of react-router-redux, so you need to run `npm install` from there first. If you want to use a version straight from npm, remove the lines in `webpack.config.js` at the bottom.
3. Build with `webpack --watch`
4. Open `index.html`
3. Start build with `npm start`
4. Open [http://localhost:8080/](http://localhost:8080/)

-

Expand Down
21 changes: 9 additions & 12 deletions examples/basic/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,35 @@ import DockMonitor from 'redux-devtools-dock-monitor'

import React from 'react'
import ReactDOM from 'react-dom'
import { applyMiddleware, compose, createStore, combineReducers } from 'redux'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import { Router, Route, IndexRoute, browserHistory } from 'react-router'
import { syncHistory, routeReducer } from 'react-router-redux'
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'

import * as reducers from './reducers'
import { App, Home, Foo, Bar } from './components'

const middleware = syncHistory(browserHistory)
const reducer = combineReducers({
...reducers,
routing: routeReducer
routing: routerReducer
})

const DevTools = createDevTools(
<DockMonitor toggleVisibilityKey="ctrl-h"
changePositionKey="ctrl-q">
<DockMonitor toggleVisibilityKey="ctrl-h" changePositionKey="ctrl-q">
<LogMonitor theme="tomorrow" preserveScrollTop={false} />
</DockMonitor>
)

const finalCreateStore = compose(
applyMiddleware(middleware),
const store = createStore(
reducer,
DevTools.instrument()
)(createStore)
const store = finalCreateStore(reducer)
middleware.listenForReplays(store)
)
const history = syncHistoryWithStore(browserHistory, store)

ReactDOM.render(
<Provider store={store}>
<div>
<Router history={browserHistory}>
<Router history={history}>
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="foo" component={Foo}/>
Expand Down
13 changes: 3 additions & 10 deletions examples/basic/components/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react'
import { Link } from 'react-router'
import { connect } from 'react-redux'
import { routeActions } from 'react-router-redux'
import { Link, hashHistory } from 'react-router'

function App({ push, children }) {
export default function App({ children }) {
return (
<div>
<header>
Expand All @@ -16,14 +14,9 @@ function App({ push, children }) {
<Link to="/bar">Bar</Link>
</header>
<div>
<button onClick={() => push('/foo')}>Go to /foo</button>
<button onClick={() => hashHistory.push('/foo')}>Go to /foo</button>
</div>
<div style={{ marginTop: '1.5em' }}>{children}</div>
</div>
)
}

export default connect(
null,
routeActions
)(App)
2 changes: 1 addition & 1 deletion examples/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</head>
<body>
<div id="mount"></div>
<script src="dist/bundle.js"></script>
<script src="/bundle.js"></script>
</body>
</html>
31 changes: 16 additions & 15 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
"repository": "reactjs/react-router-redux",
"license": "MIT",
"dependencies": {
"react": "^0.14.2",
"react-dom": "^0.14.2",
"react-redux": "^4.0.0",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-redux": "^4.3.0",
"react-router": "^2.0.0",
"redux": "^3.0.4",
"react-router-redux": "^2.1.0"
"redux": "^3.2.1",
"react-router-redux": "^3.0.0"
},
"devDependencies": {
"babel-core": "^6.1.21",
"babel-eslint": "^5.0.0-beta6",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"babel-core": "^6.4.5",
"babel-eslint": "^5.0.0-beta9",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-1": "^6.3.13",
"eslint": "^1.10.3",
"eslint-config-rackt": "^1.1.1",
"eslint-plugin-react": "^3.15.0",
"redux-devtools": "^3.0.0",
"eslint-plugin-react": "^3.16.1",
"redux-devtools": "^3.1.0",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.1",
"webpack": "^1.12.6"
"redux-devtools-log-monitor": "^1.0.4",
"webpack": "^1.12.13",
"webpack-dev-server": "^1.14.1"
},
"scripts": {
"start": "webpack --watch"
"start": "webpack-dev-server --history-api-fallback --no-info --open"
}
}
8 changes: 8 additions & 0 deletions examples/server/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["es2015", "react", "stage-1"],
"plugins": [
["babel-plugin-module-alias", [
{ "src": "../../src", "expose": "react-router-redux" }
]]
]
}
28 changes: 28 additions & 0 deletions examples/server/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'babel-polyfill'

import React from 'react'
import { render } from 'react-dom'

import { Provider } from 'react-redux'
import { Router, browserHistory } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'

import { configureStore, DevTools } from './store'
import routes from './routes'

const store = configureStore(browserHistory, window.__initialState__)
const history = syncHistoryWithStore(browserHistory, store)

render(
<Provider store={store}>
<Router history={history} routes={routes} />
</Provider>,
document.getElementById('root')
)

render(
<Provider store={store}>
<DevTools/>
</Provider>,
document.getElementById('devtools')
)
11 changes: 11 additions & 0 deletions examples/server/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>react-router-redux server rendering example</title>
<meta charset="utf8"/>
</head>
<body>
<div id="root"></div>
<script src="/bundle.js"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions examples/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "rrr-server-example",
"version": "0.0.0",
"repository": "reactjs/react-router-redux",
"license": "MIT",
"dependencies": {
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-redux": "^4.3.0",
"react-router": "^2.0.0",
"react-router-redux": "^3.0.0",
"redux": "^3.2.1",
"serialize-javascript": "^1.1.2"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-core": "^6.4.5",
"babel-eslint": "^5.0.0-beta9",
"babel-loader": "^6.2.2",
"babel-plugin-module-alias": "^1.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-1": "^6.3.13",
"babel-register": "^6.5.2",
"eslint": "^1.10.3",
"eslint-config-rackt": "^1.1.1",
"eslint-plugin-react": "^3.16.1",
"express": "^4.13.4",
"redux-devtools": "^3.1.1",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.4",
"webpack": "^1.12.13",
"webpack-dev-middleware": "^1.5.1"
},
"scripts": {
"start": "babel-node server.js"
}
}
31 changes: 31 additions & 0 deletions examples/server/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'
import { Route, IndexRoute, Link } from 'react-router'

const App = ({ children }) => (
<div>
<header>
Links:
{' '}
<Link to="/">Home</Link>
{' '}
<Link to="/foo">Foo</Link>
{' '}
<Link to="/bar">Bar</Link>
</header>
{children}
</div>
)

const Home = () => (<div>Home!</div>)
const Foo = () => (<div>Foo!</div>)
const Bar = () => (<div>Bar!</div>)

const routes = (
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="foo" component={Foo}/>
<Route path="bar" component={Bar}/>
</Route>
)

export default routes
62 changes: 62 additions & 0 deletions examples/server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*eslint-disable no-console */
import express from 'express'
import serialize from 'serialize-javascript'

import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackConfig from './webpack.config'

import React from 'react'
import { renderToString } from 'react-dom/server'
import { Provider } from 'react-redux'
import { createMemoryHistory, match, RouterContext } from 'react-router'
import { syncHistoryWithStore } from '../../src'

import { configureStore } from './store'
import routes from './routes'

const app = express()

app.use(webpackDevMiddleware(webpack(webpackConfig), {
publicPath: '/__build__/',
stats: {
colors: true
}
}))

const HTML = ({ content, store }) => (
<html>
<body>
<div id="root" dangerouslySetInnerHTML={{ __html: content }}/>
<div id="devtools"/>
<script dangerouslySetInnerHTML={{ __html: `window.__initialState__=${serialize(store.getState())};` }}/>
<script src="/__build__/bundle.js"/>
</body>
</html>
)

app.use(function (req, res) {
const memoryHistory = createMemoryHistory(req.path)
const store = configureStore(memoryHistory)
const history = syncHistoryWithStore(memoryHistory, store)

match({ history, routes, location: req.url }, (error, redirectLocation, renderProps) => {
if (error) {
res.status(500).send(error.message)
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search)
} else if (renderProps) {
const content = renderToString(
<Provider store={store}>
<RouterContext {...renderProps}/>
</Provider>
)

res.send('<!doctype html>\n' + renderToString(<HTML content={content} store={store}/>))
}
})
})

app.listen(8080, function () {
console.log('Server listening on http://localhost:8080, Ctrl+C to stop')
})
38 changes: 38 additions & 0 deletions examples/server/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'

import { createStore, combineReducers, compose, applyMiddleware } from 'redux'
import { createDevTools } from 'redux-devtools'
import LogMonitor from 'redux-devtools-log-monitor'
import DockMonitor from 'redux-devtools-dock-monitor'

import { routerReducer, routerMiddleware } from 'react-router-redux'

export const DevTools = createDevTools(
<DockMonitor toggleVisibilityKey="ctrl-h" changePositionKey="ctrl-q">
<LogMonitor theme="tomorrow" preserveScrollTop={false} />
</DockMonitor>
)

export function configureStore(history, initialState) {
const reducer = combineReducers({
routing: routerReducer
})

let devTools = []
if (typeof document !== 'undefined') {
devTools = [ DevTools.instrument() ]
}

const store = createStore(
reducer,
initialState,
compose(
applyMiddleware(
routerMiddleware(history)
),
...devTools
)
)

return store
}
Loading