├── .babelrc ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENSE.md ├── README.md ├── examples ├── counter │ ├── .babelrc │ ├── README.md │ ├── actions │ │ └── CounterActions.js │ ├── components │ │ └── Counter.js │ ├── constants │ │ └── ActionTypes.js │ ├── containers │ │ ├── App.js │ │ └── CounterApp.js │ ├── index.html │ ├── index.js │ ├── package.json │ ├── reducers │ │ ├── counter.js │ │ └── index.js │ ├── server.js │ └── webpack.config.js └── todomvc │ ├── .babelrc │ ├── README.md │ ├── actions │ └── TodoActions.js │ ├── components │ ├── Footer.js │ ├── Header.js │ ├── MainSection.js │ ├── TodoItem.js │ └── TodoTextInput.js │ ├── constants │ ├── ActionTypes.js │ └── TodoFilters.js │ ├── containers │ ├── App.js │ └── TodoApp.js │ ├── index.html │ ├── index.js │ ├── package.json │ ├── reducers │ ├── index.js │ └── todos.js │ ├── server.js │ └── webpack.config.js ├── package.json ├── src ├── createDevTools.js ├── devTools.js ├── index.js ├── persistState.js ├── react │ ├── DebugPanel.js │ ├── JSONTree │ │ ├── JSONArrayNode.js │ │ ├── JSONArrow.js │ │ ├── JSONBooleanNode.js │ │ ├── JSONIterableNode.js │ │ ├── JSONNullNode.js │ │ ├── JSONNumberNode.js │ │ ├── JSONObjectNode.js │ │ ├── JSONStringNode.js │ │ ├── grab-node.js │ │ ├── index.js │ │ ├── mixins │ │ │ ├── expanded-state-handler.js │ │ │ ├── index.js │ │ │ └── squash-click-event.js │ │ └── obj-type.js │ ├── LogMonitor.js │ ├── LogMonitorButton.js │ ├── LogMonitorEntry.js │ ├── LogMonitorEntryAction.js │ ├── index.js │ ├── native │ │ └── index.js │ ├── theme.js │ └── themes │ │ ├── apathy.js │ │ ├── ashes.js │ │ ├── atelier-dune.js │ │ ├── atelier-forest.js │ │ ├── atelier-heath.js │ │ ├── atelier-lakeside.js │ │ ├── atelier-seaside.js │ │ ├── bespin.js │ │ ├── brewer.js │ │ ├── bright.js │ │ ├── chalk.js │ │ ├── codeschool.js │ │ ├── colors.js │ │ ├── default.js │ │ ├── eighties.js │ │ ├── embers.js │ │ ├── flat.js │ │ ├── google.js │ │ ├── grayscale.js │ │ ├── greenscreen.js │ │ ├── harmonic.js │ │ ├── hopscotch.js │ │ ├── index.js │ │ ├── isotope.js │ │ ├── marrakesh.js │ │ ├── mocha.js │ │ ├── monokai.js │ │ ├── nicinabox.js │ │ ├── ocean.js │ │ ├── paraiso.js │ │ ├── pop.js │ │ ├── railscasts.js │ │ ├── shapeshifter.js │ │ ├── solarized.js │ │ ├── summerfruit.js │ │ ├── threezerotwofour.js │ │ ├── tomorrow.js │ │ ├── tube.js │ │ └── twilight.js └── utils │ ├── brighten.js │ ├── deepEqual.js │ └── hexToRgb.js └── test └── index.spec.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "stage": 0, 3 | "loose": "all" 4 | } 5 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | lib 2 | **/node_modules 3 | **/webpack.config.js 4 | examples/**/server.js -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-airbnb", 3 | "env": { 4 | "browser": true, 5 | "mocha": true, 6 | "node": true 7 | }, 8 | "rules": { 9 | "react/jsx-uses-react": 2, 10 | "react/jsx-uses-vars": 2, 11 | "react/react-in-jsx-scope": 2, 12 | "no-console": 0, 13 | // Temporarily disabled due to babel-eslint issues: 14 | "block-scoped-var": 0, 15 | "padded-blocks": 0, 16 | }, 17 | "plugins": [ 18 | "react" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | lib 5 | coverage 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | src 4 | test 5 | examples 6 | coverage 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "iojs" 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | All notable changes to this project will be documented in this file. 4 | This project adheres to [Semantic Versioning](http://semver.org/). 5 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 14 | 15 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dan Abramov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Redux DevTools 2 | ========================= 3 | 4 | A live-editing time travel environment for [Redux](https://github.com/rackt/redux). 5 | **[See Dan's React Europe talk demoing it!](http://youtube.com/watch?v=xsSnOQynTHs)** 6 | 7 | ![](http://i.imgur.com/J4GeW0M.gif) 8 | 9 | ### Features 10 | 11 | * Lets you inspect every state and action payload 12 | * Lets you go back in time by “cancelling” actions 13 | * If you change the reducer code, each “staged” action will be re-evaluted 14 | * If the reducers throw, you will see during which action this happened, and what the error was 15 | * With `persistState()` store enhancer, you can persist debug sessions across page reloads 16 | * To monitor a part of the state, you can set a `select` prop on the DevTools component: ` state.todos} store={store} monitor={LogMonitor} />` 17 | 18 | ### Installation 19 | 20 | ``` 21 | npm install --save-dev redux-devtools 22 | ``` 23 | 24 | DevTools is a [store enhancer](http://rackt.github.io/redux/docs/Glossary.html#store-enhancer), which should be added to your middleware stack *after* [`applyMiddleware`](http://rackt.github.io/redux/docs/api/applyMiddleware.html) as `applyMiddleware` is potentially asynchronous. Otherwise, DevTools won’t see the raw actions emitted by asynchronous middleware such as [redux-promise](https://github.com/acdlite/redux-promise) or [redux-thunk](https://github.com/gaearon/redux-thunk). 25 | 26 | To install, firstly import `devTools` into your root React component: 27 | 28 | ```js 29 | // Redux utility functions 30 | import { compose, createStore, applyMiddleware } from 'redux'; 31 | // Redux DevTools store enhancers 32 | import { devTools, persistState } from 'redux-devtools'; 33 | // React components for Redux DevTools 34 | import { DevTools, DebugPanel, LogMonitor } from 'redux-devtools/lib/react'; 35 | ``` 36 | 37 | Then, add `devTools` to your store enhancers, and create your store: 38 | 39 | ```js 40 | const finalCreateStore = compose( 41 | // Enables your middleware: 42 | applyMiddleware(thunk), 43 | // Provides support for DevTools: 44 | devTools(), 45 | // Lets you write ?debug_session= in address bar to persist debug sessions 46 | persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)), 47 | createStore 48 | ); 49 | 50 | const store = finalCreateStore(reducer); 51 | ``` 52 | 53 | Finally, include the `DevTools` in your page. You may pass either `LogMonitor` (the default one) or any of the custom monitors described below. For convenience, you can use `DebugPanel` to dock `DevTools` to some part of the screen, but you can put it also somewhere else in the component tree. 54 | 55 | ```js 56 | export default class Root extends Component { 57 | render() { 58 | return ( 59 |
60 | 61 | {() => } 62 | 63 | 64 | 65 | 66 |
67 | ); 68 | } 69 | } 70 | ``` 71 | 72 | [This commit](https://github.com/gaearon/redux-devtools/commit/0a2a97556e252bfad822ca438923774bc8b932a4) should give you an idea about how to add Redux DevTools for your app **but make sure to only apply `devTools()` in development!** In production, this will be terribly slow because actions just accumulate forever. (We'll need to implement a rolling window for dev too.) 73 | 74 | For example, in Webpack, you can use `DefinePlugin` to turn magic constants like `__DEV__` into `true` or `false` depending on the environment, and import and render `redux-devtools` conditionally behind `if (__DEV__)`. Then, if you have an Uglify step before production, Uglify will eliminate dead `if (false)` branches with `redux-devtools` imports. Here is [an example](https://github.com/erikras/react-redux-universal-hot-example/compare/66bf63fb0f23a3c264a5d37c3acb4c047bf0c0c9...c6515236a1def8a3d2bfeb8f6cd6f0ccdb2f9e1b) of adding React DevTools to a project handling the production case correctly. 75 | 76 | ### Running Examples 77 | 78 | You can do this: 79 | 80 | ``` 81 | git clone https://github.com/gaearon/redux-devtools.git 82 | cd redux-devtools 83 | npm install 84 | 85 | cd examples/counter 86 | npm install 87 | npm start 88 | open http://localhost:3000 89 | ``` 90 | 91 | Try clicking on actions in the log, or changing some code inside `examples/counter/reducers/counter`. 92 | For fun, you can also open `http://localhost:3000/?debug_session=123`, click around, and then refresh. 93 | 94 | Oh, and you can do the same with the TodoMVC example as well. 95 | 96 | ### Custom Monitors 97 | 98 | **You can build a completely custom UI for it** because `` accepts a `monitor` React component prop. The included `LogMonitor` is just an example. 99 | 100 | **[I challenge you to build a custom monitor for Redux DevTools!](https://github.com/gaearon/redux-devtools/issues/3)** 101 | 102 | Some crazy ideas for custom monitors: 103 | 104 | * A slider that lets you jump between computed states just by dragging it 105 | * An in-app layer that shows the last N states right in the app (e.g. for animation) 106 | * A time machine like interface where the last N states of your app reside on different Z layers 107 | * Feel free to come up with and implement your own! Check `LogMonitor` propTypes to see what you can do. 108 | 109 | In fact some of these are implemented already: 110 | 111 | #### [redux-devtools-diff-monitor](https://github.com/whetstone/redux-devtools-diff-monitor) 112 | 113 | ![](http://i.imgur.com/rvCR9OQ.png) 114 | 115 | #### [redux-slider-monitor](https://github.com/calesce/redux-slider-monitor) 116 | 117 | ![](https://camo.githubusercontent.com/d61984306d27d5e0739efc2d57c56ba7aed7996c/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f662e636c2e6c792f6974656d732f3269314c3147316e3161316833793161324f31772f53637265656e2532305265636f7264696e67253230323031352d30382d3034253230617425323030372e3435253230504d2e676966) 118 | 119 | #### [redux-devtools-gentest-plugin](https://github.com/lapanoid/redux-devtools-gentest-plugin) 120 | 121 | ![](https://camo.githubusercontent.com/71452cc55bc2ac2016dc05e4b6207c5777028a67/687474703a2f2f646c312e6a6f78692e6e65742f64726976652f303031302f333937372f3639323130352f3135303731362f643235343637613236362e706e67) 122 | 123 | #### Keep them coming! 124 | 125 | Create a PR to add your custom monitor. 126 | 127 | ### License 128 | 129 | MIT 130 | -------------------------------------------------------------------------------- /examples/counter/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "stage": 0 3 | } 4 | -------------------------------------------------------------------------------- /examples/counter/README.md: -------------------------------------------------------------------------------- 1 | # Redux DevTools Counter example 2 | 3 | ## Getting Started 4 | 5 | 1. Install dependencies: `npm i` 6 | 2. Start the development server: `npm start` 7 | -------------------------------------------------------------------------------- /examples/counter/actions/CounterActions.js: -------------------------------------------------------------------------------- 1 | import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes'; 2 | 3 | export function increment() { 4 | return { 5 | type: INCREMENT_COUNTER 6 | }; 7 | } 8 | 9 | export function decrement() { 10 | return { 11 | type: DECREMENT_COUNTER 12 | }; 13 | } 14 | 15 | export function incrementIfOdd() { 16 | return (dispatch, getState) => { 17 | const { counter } = getState(); 18 | 19 | if (counter % 2 === 0) { 20 | return; 21 | } 22 | 23 | dispatch(increment()); 24 | }; 25 | } 26 | 27 | export function incrementAsync() { 28 | return dispatch => { 29 | setTimeout(() => { 30 | dispatch(increment()); 31 | }, 1000); 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /examples/counter/components/Counter.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | 3 | export default class Counter extends Component { 4 | static propTypes = { 5 | increment: PropTypes.func.isRequired, 6 | incrementIfOdd: PropTypes.func.isRequired, 7 | decrement: PropTypes.func.isRequired, 8 | counter: PropTypes.number.isRequired 9 | }; 10 | 11 | render() { 12 | const { increment, incrementIfOdd, decrement, counter } = this.props; 13 | return ( 14 |

15 | Clicked: {counter} times 16 | {' '} 17 | 18 | {' '} 19 | 20 | {' '} 21 | 22 |

23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/counter/constants/ActionTypes.js: -------------------------------------------------------------------------------- 1 | export const INCREMENT_COUNTER = 'INCREMENT_COUNTER'; 2 | export const DECREMENT_COUNTER = 'DECREMENT_COUNTER'; 3 | -------------------------------------------------------------------------------- /examples/counter/containers/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import CounterApp from './CounterApp'; 3 | import { createStore, applyMiddleware, combineReducers, compose } from 'redux'; 4 | import { devTools, persistState } from 'redux-devtools'; 5 | import { DevTools, DebugPanel, LogMonitor } from 'redux-devtools/lib/react'; 6 | import thunk from 'redux-thunk'; 7 | import { Provider } from 'react-redux'; 8 | import * as reducers from '../reducers'; 9 | 10 | const finalCreateStore = compose( 11 | applyMiddleware(thunk), 12 | devTools(), 13 | persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)), 14 | createStore 15 | ); 16 | 17 | const reducer = combineReducers(reducers); 18 | const store = finalCreateStore(reducer); 19 | 20 | export default class App extends Component { 21 | render() { 22 | return ( 23 |
24 | 25 | {() => } 26 | 27 | 28 | 30 | 31 |
32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/counter/containers/CounterApp.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { bindActionCreators } from 'redux'; 3 | import { connect } from 'react-redux'; 4 | import Counter from '../components/Counter'; 5 | import * as CounterActions from '../actions/CounterActions'; 6 | 7 | class CounterApp extends Component { 8 | render() { 9 | const { counter, dispatch } = this.props; 10 | return ( 11 | 13 | ); 14 | } 15 | } 16 | 17 | function select(state) { 18 | return { 19 | counter: state.counter 20 | }; 21 | } 22 | 23 | export default connect(select)(CounterApp); 24 | -------------------------------------------------------------------------------- /examples/counter/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Redux Counter Example 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/counter/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './containers/App'; 3 | 4 | React.render( 5 | , 6 | document.getElementById('root') 7 | ); 8 | -------------------------------------------------------------------------------- /examples/counter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "counter-redux", 3 | "version": "0.0.0", 4 | "description": "Counter example for redux", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/gaearon/redux-devtools.git" 12 | }, 13 | "license": "MIT", 14 | "bugs": { 15 | "url": "https://github.com/gaearon/redux-devtools/issues" 16 | }, 17 | "homepage": "https://github.com/gaearon/redux-devtools#readme", 18 | "dependencies": { 19 | "react": "^0.13.3", 20 | "react-redux": "^0.9.0", 21 | "redux": "^1.0.1", 22 | "redux-thunk": "^0.1.0" 23 | }, 24 | "devDependencies": { 25 | "babel-core": "^5.6.18", 26 | "babel-loader": "^5.1.4", 27 | "node-libs-browser": "^0.5.2", 28 | "react-hot-loader": "^1.2.7", 29 | "webpack": "^1.9.11", 30 | "webpack-dev-server": "^1.9.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/counter/reducers/counter.js: -------------------------------------------------------------------------------- 1 | import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes'; 2 | 3 | export default function counter(state = 0, action) { 4 | switch (action.type) { 5 | case INCREMENT_COUNTER: 6 | return state + 1; 7 | case DECREMENT_COUNTER: 8 | return state - 1; 9 | default: 10 | return state; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/counter/reducers/index.js: -------------------------------------------------------------------------------- 1 | export { default as counter } from './counter'; 2 | -------------------------------------------------------------------------------- /examples/counter/server.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); 2 | var WebpackDevServer = require('webpack-dev-server'); 3 | var config = require('./webpack.config'); 4 | 5 | new WebpackDevServer(webpack(config), { 6 | publicPath: config.output.publicPath, 7 | hot: true, 8 | historyApiFallback: true, 9 | stats: { 10 | colors: true 11 | } 12 | }).listen(3000, 'localhost', function (err) { 13 | if (err) { 14 | console.log(err); 15 | } 16 | 17 | console.log('Listening at localhost:3000'); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/counter/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | 4 | module.exports = { 5 | devtool: 'eval', 6 | entry: [ 7 | 'webpack-dev-server/client?http://localhost:3000', 8 | 'webpack/hot/only-dev-server', 9 | './index' 10 | ], 11 | output: { 12 | path: path.join(__dirname, 'dist'), 13 | filename: 'bundle.js', 14 | publicPath: '/static/' 15 | }, 16 | plugins: [ 17 | new webpack.HotModuleReplacementPlugin(), 18 | new webpack.NoErrorsPlugin() 19 | ], 20 | resolve: { 21 | alias: { 22 | 'redux-devtools/lib': path.join(__dirname, '..', '..', 'src'), 23 | 'redux-devtools': path.join(__dirname, '..', '..', 'src'), 24 | 'react': path.join(__dirname, 'node_modules', 'react') 25 | }, 26 | extensions: ['', '.js'] 27 | }, 28 | resolveLoader: { 29 | 'fallback': path.join(__dirname, 'node_modules') 30 | }, 31 | module: { 32 | loaders: [{ 33 | test: /\.js$/, 34 | loaders: ['react-hot', 'babel'], 35 | exclude: /node_modules/, 36 | include: __dirname 37 | }, { 38 | test: /\.js$/, 39 | loaders: ['react-hot', 'babel'], 40 | include: path.join(__dirname, '..', '..', 'src') 41 | }] 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /examples/todomvc/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "stage": 0 3 | } 4 | -------------------------------------------------------------------------------- /examples/todomvc/README.md: -------------------------------------------------------------------------------- 1 | # Redux DevTools TodoMVC example 2 | 3 | ## Getting Started 4 | 5 | 1. Install dependencies: `npm i` 6 | 2. Start the development server: `npm start` 7 | -------------------------------------------------------------------------------- /examples/todomvc/actions/TodoActions.js: -------------------------------------------------------------------------------- 1 | import * as types from '../constants/ActionTypes'; 2 | 3 | export function addTodo(text) { 4 | return { 5 | type: types.ADD_TODO, 6 | text 7 | }; 8 | } 9 | 10 | export function deleteTodo(id) { 11 | return { 12 | type: types.DELETE_TODO, 13 | id 14 | }; 15 | } 16 | 17 | export function editTodo(id, text) { 18 | return { 19 | type: types.EDIT_TODO, 20 | id, 21 | text 22 | }; 23 | } 24 | 25 | export function markTodo(id) { 26 | return { 27 | type: types.MARK_TODO, 28 | id 29 | }; 30 | } 31 | 32 | export function markAll() { 33 | return { 34 | type: types.MARK_ALL 35 | }; 36 | } 37 | 38 | export function clearMarked() { 39 | return { 40 | type: types.CLEAR_MARKED 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /examples/todomvc/components/Footer.js: -------------------------------------------------------------------------------- 1 | import React, { PropTypes, Component } from 'react'; 2 | import classnames from 'classnames'; 3 | import { SHOW_ALL, SHOW_MARKED, SHOW_UNMARKED } from '../constants/TodoFilters'; 4 | 5 | const FILTER_TITLES = { 6 | [SHOW_ALL]: 'All', 7 | [SHOW_UNMARKED]: 'Active', 8 | [SHOW_MARKED]: 'Completed' 9 | }; 10 | 11 | export default class Footer extends Component { 12 | static propTypes = { 13 | markedCount: PropTypes.number.isRequired, 14 | unmarkedCount: PropTypes.number.isRequired, 15 | filter: PropTypes.string.isRequired, 16 | onClearMarked: PropTypes.func.isRequired, 17 | onShow: PropTypes.func.isRequired 18 | } 19 | 20 | render() { 21 | return ( 22 |
23 | {this.renderTodoCount()} 24 |
    25 | {[SHOW_ALL, SHOW_UNMARKED, SHOW_MARKED].map(filter => 26 |
  • 27 | {this.renderFilterLink(filter)} 28 |
  • 29 | )} 30 |
31 | {this.renderClearButton()} 32 |
33 | ); 34 | } 35 | 36 | renderTodoCount() { 37 | const { unmarkedCount } = this.props; 38 | const itemWord = unmarkedCount === 1 ? 'item' : 'items'; 39 | 40 | return ( 41 | 42 | {unmarkedCount || 'No'} {itemWord} left 43 | 44 | ); 45 | } 46 | 47 | renderFilterLink(filter) { 48 | const title = FILTER_TITLES[filter]; 49 | const { filter: selectedFilter, onShow } = this.props; 50 | 51 | return ( 52 | onShow(filter)}> 55 | {title} 56 | 57 | ); 58 | } 59 | 60 | renderClearButton() { 61 | const { markedCount, onClearMarked } = this.props; 62 | if (markedCount > 0) { 63 | return ( 64 | 68 | ); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /examples/todomvc/components/Header.js: -------------------------------------------------------------------------------- 1 | import React, { PropTypes, Component } from 'react'; 2 | import TodoTextInput from './TodoTextInput'; 3 | 4 | export default class Header extends Component { 5 | static propTypes = { 6 | addTodo: PropTypes.func.isRequired 7 | }; 8 | 9 | handleSave(text) { 10 | if (text.length !== 0) { 11 | this.props.addTodo(text); 12 | } 13 | } 14 | 15 | render() { 16 | return ( 17 |
18 |

todos

19 | 22 |
23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/todomvc/components/MainSection.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | import TodoItem from './TodoItem'; 3 | import Footer from './Footer'; 4 | import { SHOW_ALL, SHOW_MARKED, SHOW_UNMARKED } from '../constants/TodoFilters'; 5 | 6 | const TODO_FILTERS = { 7 | [SHOW_ALL]: () => true, 8 | [SHOW_UNMARKED]: todo => !todo.marked, 9 | [SHOW_MARKED]: todo => todo.marked 10 | }; 11 | 12 | export default class MainSection extends Component { 13 | static propTypes = { 14 | todos: PropTypes.array.isRequired, 15 | actions: PropTypes.object.isRequired 16 | }; 17 | 18 | constructor(props, context) { 19 | super(props, context); 20 | this.state = { filter: SHOW_ALL }; 21 | } 22 | 23 | handleClearMarked() { 24 | const atLeastOneMarked = this.props.todos.some(todo => todo.marked); 25 | if (atLeastOneMarked) { 26 | this.props.actions.clearMarked(); 27 | } 28 | } 29 | 30 | handleShow(filter) { 31 | this.setState({ filter }); 32 | } 33 | 34 | render() { 35 | const { todos, actions } = this.props; 36 | const { filter } = this.state; 37 | 38 | const filteredTodos = todos.filter(TODO_FILTERS[filter]); 39 | const markedCount = todos.reduce((count, todo) => 40 | todo.marked ? count + 1 : count, 41 | 0 42 | ); 43 | 44 | return ( 45 |
46 | {this.renderToggleAll(markedCount)} 47 |
    48 | {filteredTodos.map(todo => 49 | 50 | )} 51 |
52 | {this.renderFooter(markedCount)} 53 |
54 | ); 55 | } 56 | 57 | renderToggleAll(markedCount) { 58 | const { todos, actions } = this.props; 59 | if (todos.length > 0) { 60 | return ( 61 | 65 | ); 66 | } 67 | } 68 | 69 | renderFooter(markedCount) { 70 | const { todos } = this.props; 71 | const { filter } = this.state; 72 | const unmarkedCount = todos.length - markedCount; 73 | 74 | if (todos.length) { 75 | return ( 76 |