├── .eslintrc ├── examples ├── .gitignore ├── basic │ ├── reducers │ │ ├── index.js │ │ └── count.js │ ├── .babelrc │ ├── constants.js │ ├── components │ │ ├── Foo.js │ │ ├── Bar.js │ │ ├── index.js │ │ ├── Home.js │ │ └── App.js │ ├── index.html │ ├── actions │ │ └── count.js │ ├── webpack.config.js │ ├── package.json │ ├── README.md │ └── app.js └── server │ ├── .babelrc │ ├── index.html │ ├── routes.js │ ├── client.js │ ├── webpack.config.js │ ├── store.js │ ├── package.json │ └── server.js ├── .eslintignore ├── .gitignore ├── test ├── .eslintrc ├── sync.spec.js ├── browser │ └── index.js ├── middleware.spec.js ├── reducer.spec.js ├── actions.spec.js └── _createSyncTest.js ├── tests.webpack.js ├── .babelrc ├── .editorconfig ├── src ├── index.js ├── middleware.js ├── reducer.js ├── actions.js └── sync.js ├── .travis.yml ├── webpack.config.js ├── LICENSE ├── karma.conf.js ├── package.json ├── CHANGELOG.md └── README.md /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "react-app" 3 | } 4 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | *.log 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | examples/*/node_modules/ 2 | examples/*/dist/ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | dist 3 | node_modules 4 | coverage 5 | *.log 6 | -------------------------------------------------------------------------------- /examples/basic/reducers/index.js: -------------------------------------------------------------------------------- 1 | export count from './count' 2 | -------------------------------------------------------------------------------- /test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/basic/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "react", "stage-1"] 3 | } 4 | -------------------------------------------------------------------------------- /examples/basic/constants.js: -------------------------------------------------------------------------------- 1 | 2 | export const INCREASE = 'INCREASE' 3 | export const DECREASE = 'DECREASE' 4 | -------------------------------------------------------------------------------- /tests.webpack.js: -------------------------------------------------------------------------------- 1 | const browserContext = require.context('./test/browser') 2 | browserContext.keys().forEach(browserContext) 3 | -------------------------------------------------------------------------------- /examples/basic/components/Foo.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default function Foo() { 4 | return
I am Foo!
5 | } 6 | -------------------------------------------------------------------------------- /examples/basic/components/Bar.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default function Bar() { 4 | return
And I am Bar!
5 | } 6 | -------------------------------------------------------------------------------- /examples/basic/components/index.js: -------------------------------------------------------------------------------- 1 | export App from './App' 2 | export Home from './Home' 3 | export Foo from './Foo' 4 | export Bar from './Bar' 5 | -------------------------------------------------------------------------------- /test/sync.spec.js: -------------------------------------------------------------------------------- 1 | import { createMemoryHistory } from 'history' 2 | import createTests from './_createSyncTest' 3 | 4 | createTests(createMemoryHistory, 'Memory History') 5 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "react", "stage-1"], 3 | "plugins": [ 4 | "transform-es3-member-expression-literals", 5 | "transform-es3-property-literals" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /examples/server/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "react", "stage-1"], 3 | "plugins": [ 4 | ["babel-plugin-module-alias", [ 5 | { "src": "../../src", "expose": "react-router-redux" } 6 | ]] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | insert_final_newline = true 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /examples/basic/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | react-router-redux basic example 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/server/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | react-router-redux server rendering example 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export syncHistoryWithStore from './sync' 2 | export { LOCATION_CHANGE, routerReducer } from './reducer' 3 | 4 | export { 5 | CALL_HISTORY_METHOD, 6 | push, replace, go, goBack, goForward, 7 | routerActions 8 | } from './actions' 9 | export routerMiddleware from './middleware' 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | branches: 3 | only: 4 | - master 5 | language: node_js 6 | cache: 7 | directories: 8 | - node_modules 9 | node_js: 10 | - "4" 11 | - "6" 12 | before_script: 13 | - export DISPLAY=:99.0 14 | - sh -e /etc/init.d/xvfb start 15 | script: 16 | - npm run test 17 | -------------------------------------------------------------------------------- /examples/basic/actions/count.js: -------------------------------------------------------------------------------- 1 | import { INCREASE, DECREASE } from '../constants' 2 | 3 | export function increase(n) { 4 | return { 5 | type: INCREASE, 6 | amount: n 7 | } 8 | } 9 | 10 | export function decrease(n) { 11 | return { 12 | type: DECREASE, 13 | amount: n 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/browser/index.js: -------------------------------------------------------------------------------- 1 | import 'babel-polyfill' 2 | 3 | import { createHashHistory, createHistory } from 'history' 4 | import createTests from '../_createSyncTest' 5 | 6 | createTests(createHashHistory, 'Hash History', () => window.location = '#/') 7 | createTests(createHistory, 'Browser History', () => window.history.replaceState(null, null, '/')) 8 | -------------------------------------------------------------------------------- /examples/basic/reducers/count.js: -------------------------------------------------------------------------------- 1 | import { INCREASE, DECREASE } from '../constants' 2 | 3 | const initialState = { 4 | number: 1 5 | } 6 | 7 | export default function update(state = initialState, action) { 8 | if(action.type === INCREASE) { 9 | return { number: state.number + action.amount } 10 | } 11 | else if(action.type === DECREASE) { 12 | return { number: state.number - action.amount } 13 | } 14 | return state 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic/components/Home.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { connect } from 'react-redux' 3 | import { increase, decrease } from '../actions/count' 4 | 5 | function Home({ number, increase, decrease }) { 6 | return ( 7 |
8 | Some state changes: 9 | {number} 10 | 11 | 12 |
13 | ) 14 | } 15 | 16 | export default connect( 17 | state => ({ number: state.count.number }), 18 | { increase, decrease } 19 | )(Home) 20 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack') 2 | 3 | var config = { 4 | entry: './src/index', 5 | module: { 6 | rules: [ 7 | { test: /\.js$/, use: [ 'babel-loader' ], exclude: /node_modules/ } 8 | ] 9 | }, 10 | output: { 11 | library: 'ReactRouterRedux', 12 | libraryTarget: 'umd' 13 | } 14 | } 15 | 16 | if (process.env.NODE_ENV === 'production') { 17 | config.plugins = [ 18 | new webpack.optimize.UglifyJsPlugin({ sourceMap: true }), 19 | new webpack.LoaderOptionsPlugin({ minimize: true }) 20 | ] 21 | } 22 | 23 | module.exports = config 24 | -------------------------------------------------------------------------------- /src/middleware.js: -------------------------------------------------------------------------------- 1 | import { CALL_HISTORY_METHOD } from './actions' 2 | 3 | /** 4 | * This middleware captures CALL_HISTORY_METHOD actions to redirect to the 5 | * provided history object. This will prevent these actions from reaching your 6 | * reducer or any middleware that comes after this one. 7 | */ 8 | export default function routerMiddleware(history) { 9 | return () => next => action => { 10 | if (action.type !== CALL_HISTORY_METHOD) { 11 | return next(action) 12 | } 13 | 14 | const { payload: { method, args } } = action 15 | history[method](...args) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/basic/components/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Link, browserHistory } from 'react-router' 3 | 4 | export default function App({ children }) { 5 | return ( 6 |
7 |
8 | Links: 9 | {' '} 10 | Home 11 | {' '} 12 | Foo 13 | {' '} 14 | Bar 15 |
16 |
17 | 18 |
19 |
{children}
20 |
21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /src/reducer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This action type will be dispatched when your history 3 | * receives a location change. 4 | */ 5 | export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE' 6 | 7 | const initialState = { 8 | locationBeforeTransitions: null 9 | } 10 | 11 | /** 12 | * This reducer will update the state with the most recent location history 13 | * has transitioned to. This may not be in sync with the router, particularly 14 | * if you have asynchronously-loaded routes, so reading from and relying on 15 | * this state is discouraged. 16 | */ 17 | export function routerReducer(state = initialState, { type, payload } = {}) { 18 | if (type === LOCATION_CHANGE) { 19 | return { ...state, locationBeforeTransitions: payload } 20 | } 21 | 22 | return state 23 | } 24 | -------------------------------------------------------------------------------- /examples/server/routes.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Route, IndexRoute, Link } from 'react-router' 3 | 4 | const App = ({ children }) => ( 5 |
6 |
7 | Links: 8 | {' '} 9 | Home 10 | {' '} 11 | Foo 12 | {' '} 13 | Bar 14 |
15 | {children} 16 |
17 | ) 18 | 19 | const Home = () => (
Home!
) 20 | const Foo = () => (
Foo!
) 21 | const Bar = () => (
Bar!
) 22 | 23 | const routes = ( 24 | 25 | 26 | 27 | 28 | 29 | ) 30 | 31 | export default routes 32 | -------------------------------------------------------------------------------- /examples/server/client.js: -------------------------------------------------------------------------------- 1 | import 'babel-polyfill' 2 | 3 | import React from 'react' 4 | import { render } from 'react-dom' 5 | 6 | import { Provider } from 'react-redux' 7 | import { Router, browserHistory } from 'react-router' 8 | import { syncHistoryWithStore } from 'react-router-redux' 9 | 10 | import { configureStore, DevTools } from './store' 11 | import routes from './routes' 12 | 13 | const store = configureStore(browserHistory, window.__initialState__) 14 | const history = syncHistoryWithStore(browserHistory, store) 15 | 16 | render( 17 | 18 | 19 | , 20 | document.getElementById('root') 21 | ) 22 | 23 | render( 24 | 25 | 26 | , 27 | document.getElementById('devtools') 28 | ) 29 | -------------------------------------------------------------------------------- /test/middleware.spec.js: -------------------------------------------------------------------------------- 1 | import expect, { createSpy } from 'expect' 2 | 3 | import { push, replace } from '../src/actions' 4 | import routerMiddleware from '../src/middleware' 5 | 6 | describe('routerMiddleware', () => { 7 | let history, next, dispatch 8 | 9 | beforeEach(() => { 10 | history = { 11 | push: createSpy(), 12 | replace: createSpy() 13 | } 14 | next = createSpy() 15 | 16 | dispatch = routerMiddleware(history)()(next) 17 | }) 18 | 19 | 20 | it('calls the appropriate history method', () => { 21 | dispatch(push('/foo')) 22 | expect(history.push).toHaveBeenCalled() 23 | 24 | dispatch(replace('/foo')) 25 | expect(history.replace).toHaveBeenCalled() 26 | 27 | expect(next).toNotHaveBeenCalled() 28 | }) 29 | 30 | it('ignores other actions', () => { 31 | dispatch({ type: 'FOO' }) 32 | expect(next).toHaveBeenCalled() 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /examples/basic/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | const path = require('path'); 3 | 4 | module.exports = { 5 | entry: './app.js', 6 | output: { 7 | path: path.join(__dirname, 'dist'), 8 | filename: 'bundle.js' 9 | }, 10 | module: { 11 | loaders: [{ 12 | test: /\.js$/, 13 | loader: 'babel', 14 | exclude: /node_modules/, 15 | include: __dirname 16 | }] 17 | } 18 | } 19 | 20 | 21 | 22 | // This will make the redux-simpler-router module resolve to the 23 | // latest src instead of using it from npm. Remove this if running 24 | // outside of the source. 25 | var src = path.join(__dirname, '..', '..', 'src') 26 | var fs = require('fs') 27 | if (fs.existsSync(src)) { 28 | // Use the latest src 29 | module.exports.resolve = { alias: { 'react-router-redux': src } } 30 | module.exports.module.loaders.push({ 31 | test: /\.js$/, 32 | loaders: ['babel'], 33 | include: src 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /src/actions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This action type will be dispatched by the history actions below. 3 | * If you're writing a middleware to watch for navigation events, be sure to 4 | * look for actions of this type. 5 | */ 6 | export const CALL_HISTORY_METHOD = '@@router/CALL_HISTORY_METHOD' 7 | 8 | function updateLocation(method) { 9 | return (...args) => ({ 10 | type: CALL_HISTORY_METHOD, 11 | payload: { method, args } 12 | }) 13 | } 14 | 15 | /** 16 | * These actions correspond to the history API. 17 | * The associated routerMiddleware will capture these events before they get to 18 | * your reducer and reissue them as the matching function on your history. 19 | */ 20 | export const push = updateLocation('push') 21 | export const replace = updateLocation('replace') 22 | export const go = updateLocation('go') 23 | export const goBack = updateLocation('goBack') 24 | export const goForward = updateLocation('goForward') 25 | 26 | export const routerActions = { push, replace, go, goBack, goForward } 27 | -------------------------------------------------------------------------------- /examples/server/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | const path = require('path') 3 | const webpack = require('webpack') 4 | 5 | module.exports = { 6 | devtool: 'inline-source-map', 7 | entry: './client.js', 8 | output: { 9 | path: path.join(__dirname, 'dist'), 10 | filename: 'bundle.js', 11 | publicPath: '/__build__/' 12 | }, 13 | module: { 14 | loaders: [{ 15 | test: /\.js$/, 16 | loader: 'babel', 17 | exclude: /node_modules/, 18 | query: { plugins: [] } 19 | }] 20 | } 21 | } 22 | 23 | 24 | // This will make the redux-simpler-router module resolve to the 25 | // latest src instead of using it from npm. Remove this if running 26 | // outside of the source. 27 | var src = path.join(__dirname, '../../src') 28 | var fs = require('fs') 29 | if (fs.existsSync(src)) { 30 | // Use the latest src 31 | module.exports.resolve = { alias: { 'react-router-redux': src } } 32 | module.exports.module.loaders.push({ 33 | test: /\.js$/, 34 | loaders: ['babel'], 35 | include: src 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /examples/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rrr-basic-example", 3 | "version": "0.0.0", 4 | "repository": "reactjs/react-router-redux", 5 | "license": "MIT", 6 | "dependencies": { 7 | "react": "^0.14.7", 8 | "react-dom": "^0.14.7", 9 | "react-redux": "^4.3.0", 10 | "react-router": "^2.0.0", 11 | "redux": "^3.2.1", 12 | "react-router-redux": "^4.0.0" 13 | }, 14 | "devDependencies": { 15 | "babel-core": "^6.4.5", 16 | "babel-eslint": "^5.0.0-beta9", 17 | "babel-loader": "^6.2.2", 18 | "babel-preset-es2015": "^6.3.13", 19 | "babel-preset-react": "^6.3.13", 20 | "babel-preset-stage-1": "^6.3.13", 21 | "eslint": "^1.10.3", 22 | "eslint-config-rackt": "^1.1.1", 23 | "eslint-plugin-react": "^3.16.1", 24 | "redux-devtools": "^3.1.0", 25 | "redux-devtools-dock-monitor": "^1.0.1", 26 | "redux-devtools-log-monitor": "^1.0.4", 27 | "webpack": "^1.12.13", 28 | "webpack-dev-server": "^1.14.1" 29 | }, 30 | "scripts": { 31 | "start": "webpack-dev-server --history-api-fallback --no-info --open" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/server/store.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import { createStore, combineReducers, compose, applyMiddleware } from 'redux' 4 | import { createDevTools } from 'redux-devtools' 5 | import LogMonitor from 'redux-devtools-log-monitor' 6 | import DockMonitor from 'redux-devtools-dock-monitor' 7 | 8 | import { routerReducer, routerMiddleware } from 'react-router-redux' 9 | 10 | export const DevTools = createDevTools( 11 | 12 | 13 | 14 | ) 15 | 16 | export function configureStore(history, initialState) { 17 | const reducer = combineReducers({ 18 | routing: routerReducer 19 | }) 20 | 21 | let devTools = [] 22 | if (typeof document !== 'undefined') { 23 | devTools = [ DevTools.instrument() ] 24 | } 25 | 26 | const store = createStore( 27 | reducer, 28 | initialState, 29 | compose( 30 | applyMiddleware( 31 | routerMiddleware(history) 32 | ), 33 | ...devTools 34 | ) 35 | ) 36 | 37 | return store 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-present James Long 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /examples/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rrr-server-example", 3 | "version": "0.0.0", 4 | "repository": "reactjs/react-router-redux", 5 | "license": "MIT", 6 | "dependencies": { 7 | "react": "^0.14.7", 8 | "react-dom": "^0.14.7", 9 | "react-redux": "^4.3.0", 10 | "react-router": "^2.0.0", 11 | "react-router-redux": "^4.0.0", 12 | "redux": "^3.2.1", 13 | "serialize-javascript": "^1.1.2" 14 | }, 15 | "devDependencies": { 16 | "babel-cli": "^6.5.1", 17 | "babel-core": "^6.4.5", 18 | "babel-eslint": "^5.0.0-beta9", 19 | "babel-loader": "^6.2.2", 20 | "babel-plugin-module-alias": "^1.2.0", 21 | "babel-preset-es2015": "^6.3.13", 22 | "babel-preset-react": "^6.3.13", 23 | "babel-preset-stage-1": "^6.3.13", 24 | "babel-register": "^6.5.2", 25 | "eslint": "^1.10.3", 26 | "eslint-config-rackt": "^1.1.1", 27 | "eslint-plugin-react": "^3.16.1", 28 | "express": "^4.13.4", 29 | "redux-devtools": "^3.1.1", 30 | "redux-devtools-dock-monitor": "^1.0.1", 31 | "redux-devtools-log-monitor": "^1.0.4", 32 | "webpack": "^1.12.13", 33 | "webpack-dev-middleware": "^1.5.1" 34 | }, 35 | "scripts": { 36 | "start": "babel-node server.js" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/basic/README.md: -------------------------------------------------------------------------------- 1 | react-router-redux basic example 2 | ================================= 3 | 4 | This is a basic example that demonstrates rendering components based 5 | on URLs with `react-router` as well as connecting them to Redux state. 6 | It uses both `` elements as well as the `push` action creator 7 | provided by react-router-redux. 8 | 9 | This example also demonstrates integration with 10 | **[redux-devtools](https://github.com/gaearon/redux-devtools) ^3.0.0** 11 | 12 | **To run, follow these steps:** 13 | 14 | 1. Install dependencies with `npm install` in this directory (make sure it creates a local node_modules) 15 | 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. 16 | 3. Start build with `npm start` 17 | 4. Open [http://localhost:8080/](http://localhost:8080/) 18 | 19 | - 20 | 21 | If you want to run the example from the npm published version of 22 | **react-router-redux**, remove the alias in `webpack.config` 23 | to the source from line 21. 24 | 25 | This example uses the latest version, switch to a specific tag to use a stable version: 26 | 27 | e.g. [react-router-redux tag 1.0.2](https://github.com/reactjs/react-router-redux/tree/1.0.2/examples/basic) 28 | -------------------------------------------------------------------------------- /test/reducer.spec.js: -------------------------------------------------------------------------------- 1 | import expect from 'expect' 2 | 3 | import { LOCATION_CHANGE, routerReducer } from '../src/reducer' 4 | 5 | describe('routerReducer', () => { 6 | const state = { 7 | locationBeforeTransitions: { 8 | pathname: '/foo', 9 | action: 'POP' 10 | } 11 | } 12 | 13 | it('updates the path', () => { 14 | expect(routerReducer(state, { 15 | type: LOCATION_CHANGE, 16 | payload: { 17 | path: '/bar', 18 | action: 'PUSH' 19 | } 20 | })).toEqual({ 21 | locationBeforeTransitions: { 22 | path: '/bar', 23 | action: 'PUSH' 24 | } 25 | }) 26 | }) 27 | 28 | it('works with initialState', () => { 29 | expect(routerReducer(undefined, { 30 | type: LOCATION_CHANGE, 31 | payload: { 32 | path: '/bar', 33 | action: 'PUSH' 34 | } 35 | })).toEqual({ 36 | locationBeforeTransitions: { 37 | path: '/bar', 38 | action: 'PUSH' 39 | } 40 | }) 41 | }) 42 | 43 | 44 | it('respects replace', () => { 45 | expect(routerReducer(state, { 46 | type: LOCATION_CHANGE, 47 | payload: { 48 | path: '/bar', 49 | action: 'REPLACE' 50 | } 51 | })).toEqual({ 52 | locationBeforeTransitions: { 53 | path: '/bar', 54 | action: 'REPLACE' 55 | } 56 | }) 57 | }) 58 | }) 59 | -------------------------------------------------------------------------------- /examples/basic/app.js: -------------------------------------------------------------------------------- 1 | import { createDevTools } from 'redux-devtools' 2 | import LogMonitor from 'redux-devtools-log-monitor' 3 | import DockMonitor from 'redux-devtools-dock-monitor' 4 | 5 | import React from 'react' 6 | import ReactDOM from 'react-dom' 7 | import { createStore, combineReducers } from 'redux' 8 | import { Provider } from 'react-redux' 9 | import { Router, Route, IndexRoute, browserHistory } from 'react-router' 10 | import { syncHistoryWithStore, routerReducer } from 'react-router-redux' 11 | 12 | import * as reducers from './reducers' 13 | import { App, Home, Foo, Bar } from './components' 14 | 15 | const reducer = combineReducers({ 16 | ...reducers, 17 | routing: routerReducer 18 | }) 19 | 20 | const DevTools = createDevTools( 21 | 22 | 23 | 24 | ) 25 | 26 | const store = createStore( 27 | reducer, 28 | DevTools.instrument() 29 | ) 30 | const history = syncHistoryWithStore(browserHistory, store) 31 | 32 | ReactDOM.render( 33 | 34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
, 45 | document.getElementById('mount') 46 | ) 47 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const path = require('path') 4 | 5 | module.exports = function (config) { 6 | 7 | let runCoverage = process.env.COVERAGE === 'true' 8 | 9 | let coverageLoaders = [] 10 | let coverageReporters = [] 11 | 12 | if (runCoverage) { 13 | coverageLoaders.push({ 14 | test: /\.js$/, 15 | include: path.resolve('src/'), 16 | loader: 'isparta' 17 | }), 18 | 19 | coverageReporters.push('coverage') 20 | } 21 | 22 | config.set({ 23 | 24 | browsers: [ 'Firefox' ], 25 | frameworks: [ 'mocha' ], 26 | reporters: [ 'mocha' ].concat(coverageReporters), 27 | 28 | files: [ 29 | 'tests.webpack.js' 30 | ], 31 | 32 | preprocessors: { 33 | 'tests.webpack.js': [ 'webpack', 'sourcemap' ] 34 | }, 35 | 36 | singleRun: true, 37 | 38 | webpack: { 39 | devtool: 'inline-source-map', 40 | module: { 41 | rules: [ 42 | { 43 | test: /\.js$/, 44 | enforce: "pre", 45 | use: 'babel-loader', 46 | include: [ 47 | path.resolve('src/'), 48 | path.resolve('test/') 49 | ] 50 | 51 | } 52 | ].concat(coverageLoaders) 53 | } 54 | }, 55 | 56 | webpackServer: { 57 | noInfo: true 58 | }, 59 | 60 | coverageReporter: { 61 | reporters: [ 62 | { type: 'text' }, 63 | { type: 'json', subdir: 'browser-coverage', file: 'coverage.json' } 64 | ] 65 | } 66 | }) 67 | } 68 | -------------------------------------------------------------------------------- /examples/server/server.js: -------------------------------------------------------------------------------- 1 | /*eslint-disable no-console */ 2 | import express from 'express' 3 | import serialize from 'serialize-javascript' 4 | 5 | import webpack from 'webpack' 6 | import webpackDevMiddleware from 'webpack-dev-middleware' 7 | import webpackConfig from './webpack.config' 8 | 9 | import React from 'react' 10 | import { renderToString } from 'react-dom/server' 11 | import { Provider } from 'react-redux' 12 | import { createMemoryHistory, match, RouterContext } from 'react-router' 13 | import { syncHistoryWithStore } from '../../src' 14 | 15 | import { configureStore } from './store' 16 | import routes from './routes' 17 | 18 | const app = express() 19 | 20 | app.use(webpackDevMiddleware(webpack(webpackConfig), { 21 | publicPath: '/__build__/', 22 | stats: { 23 | colors: true 24 | } 25 | })) 26 | 27 | const HTML = ({ content, store }) => ( 28 | 29 | 30 |
31 |
32 |