mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-22 01:26:48 +03:00
Add project skeleton (no DevTools yet)
This commit is contained in:
commit
2c7c3232e3
4
.eslintignore
Normal file
4
.eslintignore
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
lib
|
||||||
|
**/node_modules
|
||||||
|
**/webpack.config.js
|
||||||
|
examples/**/server.js
|
19
.eslintrc
Normal file
19
.eslintrc
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"extends": "eslint-config-airbnb",
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"mocha": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"react/jsx-uses-react": 2,
|
||||||
|
"react/jsx-uses-vars": 2,
|
||||||
|
"react/react-in-jsx-scope": 2,
|
||||||
|
// Temporarily disabled due to babel-eslint issues:
|
||||||
|
"block-scoped-var": 0,
|
||||||
|
"padded-blocks": 0
|
||||||
|
},
|
||||||
|
"plugins": [
|
||||||
|
"react"
|
||||||
|
]
|
||||||
|
}
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
node_modules
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
coverage
|
6
.npmignore
Normal file
6
.npmignore
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.DS_Store
|
||||||
|
*.log
|
||||||
|
src
|
||||||
|
test
|
||||||
|
examples
|
||||||
|
coverage
|
3
.travis.yml
Normal file
3
.travis.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- "iojs"
|
4
CHANGELOG.md
Normal file
4
CHANGELOG.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Change log
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
14
CODE_OF_CONDUCT.md
Normal file
14
CODE_OF_CONDUCT.md
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Contributor Code of Conduct
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||||
|
|
||||||
|
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/)
|
||||||
|
|
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Dan Abramov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
4
README.md
Normal file
4
README.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Redux DevTools
|
||||||
|
=========================
|
||||||
|
|
||||||
|
Haha. README coming.
|
3
examples/counter/.babelrc
Normal file
3
examples/counter/.babelrc
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"stage": 0
|
||||||
|
}
|
33
examples/counter/actions/CounterActions.js
Normal file
33
examples/counter/actions/CounterActions.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
||||||
|
|
||||||
|
export function increment() {
|
||||||
|
return {
|
||||||
|
type: INCREMENT_COUNTER
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function decrement() {
|
||||||
|
return {
|
||||||
|
type: DECREMENT_COUNTER
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function incrementIfOdd() {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
const { counter } = getState();
|
||||||
|
|
||||||
|
if (counter % 2 === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(increment());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function incrementAsync() {
|
||||||
|
return dispatch => {
|
||||||
|
setTimeout(() => {
|
||||||
|
dispatch(increment());
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
}
|
25
examples/counter/components/Counter.js
Normal file
25
examples/counter/components/Counter.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
|
||||||
|
export default class Counter extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
increment: PropTypes.func.isRequired,
|
||||||
|
incrementIfOdd: PropTypes.func.isRequired,
|
||||||
|
decrement: PropTypes.func.isRequired,
|
||||||
|
counter: PropTypes.number.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { increment, incrementIfOdd, decrement, counter } = this.props;
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
Clicked: {counter} times
|
||||||
|
{' '}
|
||||||
|
<button onClick={increment}>+</button>
|
||||||
|
{' '}
|
||||||
|
<button onClick={decrement}>-</button>
|
||||||
|
{' '}
|
||||||
|
<button onClick={incrementIfOdd}>Increment if odd</button>
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
2
examples/counter/constants/ActionTypes.js
Normal file
2
examples/counter/constants/ActionTypes.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
|
||||||
|
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER';
|
20
examples/counter/containers/App.js
Normal file
20
examples/counter/containers/App.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import CounterApp from './CounterApp';
|
||||||
|
import { createStore, applyMiddleware, combineReducers } from 'redux';
|
||||||
|
import thunk from 'redux-thunk';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import * as reducers from '../reducers';
|
||||||
|
|
||||||
|
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
|
||||||
|
const reducer = combineReducers(reducers);
|
||||||
|
const store = createStoreWithMiddleware(reducer);
|
||||||
|
|
||||||
|
export default class App extends Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Provider store={store}>
|
||||||
|
{() => <CounterApp />}
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
18
examples/counter/containers/CounterApp.js
Normal file
18
examples/counter/containers/CounterApp.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { bindActionCreators } from 'redux';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import Counter from '../components/Counter';
|
||||||
|
import * as CounterActions from '../actions/CounterActions';
|
||||||
|
|
||||||
|
@connect(state => ({
|
||||||
|
counter: state.counter
|
||||||
|
}))
|
||||||
|
export default class CounterApp extends Component {
|
||||||
|
render() {
|
||||||
|
const { counter, dispatch } = this.props;
|
||||||
|
return (
|
||||||
|
<Counter counter={counter}
|
||||||
|
{...bindActionCreators(CounterActions, dispatch)} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
10
examples/counter/index.html
Normal file
10
examples/counter/index.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Redux Counter Example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script src="/static/bundle.js"></script>
|
||||||
|
</html>
|
7
examples/counter/index.js
Normal file
7
examples/counter/index.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import React from 'react';
|
||||||
|
import App from './containers/App';
|
||||||
|
|
||||||
|
React.render(
|
||||||
|
<App />,
|
||||||
|
document.getElementById('root')
|
||||||
|
);
|
32
examples/counter/package.json
Normal file
32
examples/counter/package.json
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
"name": "counter-redux",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Counter example for redux",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node server.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/gaearon/redux.git"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/gaearon/redux/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/gaearon/redux#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"react": "^0.13.3",
|
||||||
|
"react-redux": "^0.2.1",
|
||||||
|
"redux": "^1.0.0-rc",
|
||||||
|
"redux-thunk": "^0.1.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-core": "^5.6.18",
|
||||||
|
"babel-loader": "^5.1.4",
|
||||||
|
"node-libs-browser": "^0.5.2",
|
||||||
|
"react-hot-loader": "^1.2.7",
|
||||||
|
"webpack": "^1.9.11",
|
||||||
|
"webpack-dev-server": "^1.9.0"
|
||||||
|
}
|
||||||
|
}
|
12
examples/counter/reducers/counter.js
Normal file
12
examples/counter/reducers/counter.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
||||||
|
|
||||||
|
export default function counter(state = 0, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case INCREMENT_COUNTER:
|
||||||
|
return state + 1;
|
||||||
|
case DECREMENT_COUNTER:
|
||||||
|
return state - 1;
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
1
examples/counter/reducers/index.js
Normal file
1
examples/counter/reducers/index.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export { default as counter } from './counter';
|
18
examples/counter/server.js
Normal file
18
examples/counter/server.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
var webpack = require('webpack');
|
||||||
|
var WebpackDevServer = require('webpack-dev-server');
|
||||||
|
var config = require('./webpack.config');
|
||||||
|
|
||||||
|
new WebpackDevServer(webpack(config), {
|
||||||
|
publicPath: config.output.publicPath,
|
||||||
|
hot: true,
|
||||||
|
historyApiFallback: true,
|
||||||
|
stats: {
|
||||||
|
colors: true
|
||||||
|
}
|
||||||
|
}).listen(3000, 'localhost', function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Listening at localhost:3000');
|
||||||
|
});
|
38
examples/counter/webpack.config.js
Normal file
38
examples/counter/webpack.config.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
var path = require('path');
|
||||||
|
var webpack = require('webpack');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
devtool: 'eval',
|
||||||
|
entry: [
|
||||||
|
'webpack-dev-server/client?http://localhost:3000',
|
||||||
|
'webpack/hot/only-dev-server',
|
||||||
|
'./index'
|
||||||
|
],
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, 'dist'),
|
||||||
|
filename: 'bundle.js',
|
||||||
|
publicPath: '/static/'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
|
new webpack.NoErrorsPlugin()
|
||||||
|
],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'redux-devtools': path.join(__dirname, '..', '..', 'src')
|
||||||
|
},
|
||||||
|
extensions: ['', '.js']
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
loaders: [{
|
||||||
|
test: /\.js$/,
|
||||||
|
loaders: ['react-hot', 'babel'],
|
||||||
|
exclude: /node_modules/,
|
||||||
|
include: __dirname
|
||||||
|
}, {
|
||||||
|
test: /\.js$/,
|
||||||
|
loaders: ['babel'],
|
||||||
|
include: path.join(__dirname, '..', '..', 'src')
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
3
examples/todomvc/.babelrc
Normal file
3
examples/todomvc/.babelrc
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"stage": 0
|
||||||
|
}
|
42
examples/todomvc/actions/TodoActions.js
Normal file
42
examples/todomvc/actions/TodoActions.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import * as types from '../constants/ActionTypes';
|
||||||
|
|
||||||
|
export function addTodo(text) {
|
||||||
|
return {
|
||||||
|
type: types.ADD_TODO,
|
||||||
|
text
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteTodo(id) {
|
||||||
|
return {
|
||||||
|
type: types.DELETE_TODO,
|
||||||
|
id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function editTodo(id, text) {
|
||||||
|
return {
|
||||||
|
type: types.EDIT_TODO,
|
||||||
|
id,
|
||||||
|
text
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function markTodo(id) {
|
||||||
|
return {
|
||||||
|
type: types.MARK_TODO,
|
||||||
|
id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function markAll() {
|
||||||
|
return {
|
||||||
|
type: types.MARK_ALL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearMarked() {
|
||||||
|
return {
|
||||||
|
type: types.CLEAR_MARKED
|
||||||
|
};
|
||||||
|
}
|
71
examples/todomvc/components/Footer.js
Normal file
71
examples/todomvc/components/Footer.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import React, { PropTypes, Component } from 'react';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
import { SHOW_ALL, SHOW_MARKED, SHOW_UNMARKED } from '../constants/TodoFilters';
|
||||||
|
|
||||||
|
const FILTER_TITLES = {
|
||||||
|
[SHOW_ALL]: 'All',
|
||||||
|
[SHOW_UNMARKED]: 'Active',
|
||||||
|
[SHOW_MARKED]: 'Completed'
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class Footer extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
markedCount: PropTypes.number.isRequired,
|
||||||
|
unmarkedCount: PropTypes.number.isRequired,
|
||||||
|
filter: PropTypes.string.isRequired,
|
||||||
|
onClearMarked: PropTypes.func.isRequired,
|
||||||
|
onShow: PropTypes.func.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<footer className='footer'>
|
||||||
|
{this.renderTodoCount()}
|
||||||
|
<ul className='filters'>
|
||||||
|
{[SHOW_ALL, SHOW_UNMARKED, SHOW_MARKED].map(filter =>
|
||||||
|
<li key={filter}>
|
||||||
|
{this.renderFilterLink(filter)}
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
{this.renderClearButton()}
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTodoCount() {
|
||||||
|
const { unmarkedCount } = this.props;
|
||||||
|
const itemWord = unmarkedCount === 1 ? 'item' : 'items';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className='todo-count'>
|
||||||
|
<strong>{unmarkedCount || 'No'}</strong> {itemWord} left
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderFilterLink(filter) {
|
||||||
|
const title = FILTER_TITLES[filter];
|
||||||
|
const { filter: selectedFilter, onShow } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a className={classnames({ selected: filter === selectedFilter })}
|
||||||
|
style={{ cursor: 'hand' }}
|
||||||
|
onClick={() => onShow(filter)}>
|
||||||
|
{title}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderClearButton() {
|
||||||
|
const { markedCount, onClearMarked } = this.props;
|
||||||
|
if (markedCount > 0) {
|
||||||
|
return (
|
||||||
|
<button className='clear-completed'
|
||||||
|
onClick={onClearMarked} >
|
||||||
|
Clear completed
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
examples/todomvc/components/Header.js
Normal file
25
examples/todomvc/components/Header.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import React, { PropTypes, Component } from 'react';
|
||||||
|
import TodoTextInput from './TodoTextInput';
|
||||||
|
|
||||||
|
export default class Header extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
addTodo: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
handleSave(text) {
|
||||||
|
if (text.length !== 0) {
|
||||||
|
this.props.addTodo(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<header className='header'>
|
||||||
|
<h1>todos</h1>
|
||||||
|
<TodoTextInput newTodo={true}
|
||||||
|
onSave={::this.handleSave}
|
||||||
|
placeholder='What needs to be done?' />
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
84
examples/todomvc/components/MainSection.js
Normal file
84
examples/todomvc/components/MainSection.js
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
import TodoItem from './TodoItem';
|
||||||
|
import Footer from './Footer';
|
||||||
|
import { SHOW_ALL, SHOW_MARKED, SHOW_UNMARKED } from '../constants/TodoFilters';
|
||||||
|
|
||||||
|
const TODO_FILTERS = {
|
||||||
|
[SHOW_ALL]: () => true,
|
||||||
|
[SHOW_UNMARKED]: todo => !todo.marked,
|
||||||
|
[SHOW_MARKED]: todo => todo.marked
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class MainSection extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
todos: PropTypes.array.isRequired,
|
||||||
|
actions: PropTypes.object.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(props, context) {
|
||||||
|
super(props, context);
|
||||||
|
this.state = { filter: SHOW_ALL };
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClearMarked() {
|
||||||
|
const atLeastOneMarked = this.props.todos.some(todo => todo.marked);
|
||||||
|
if (atLeastOneMarked) {
|
||||||
|
this.props.actions.clearMarked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShow(filter) {
|
||||||
|
this.setState({ filter });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { todos, actions } = this.props;
|
||||||
|
const { filter } = this.state;
|
||||||
|
|
||||||
|
const filteredTodos = todos.filter(TODO_FILTERS[filter]);
|
||||||
|
const markedCount = todos.reduce((count, todo) =>
|
||||||
|
todo.marked ? count + 1 : count,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className='main'>
|
||||||
|
{this.renderToggleAll(markedCount)}
|
||||||
|
<ul className='todo-list'>
|
||||||
|
{filteredTodos.map(todo =>
|
||||||
|
<TodoItem key={todo.id} todo={todo} {...actions} />
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
{this.renderFooter(markedCount)}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderToggleAll(markedCount) {
|
||||||
|
const { todos, actions } = this.props;
|
||||||
|
if (todos.length > 0) {
|
||||||
|
return (
|
||||||
|
<input className='toggle-all'
|
||||||
|
type='checkbox'
|
||||||
|
checked={markedCount === todos.length}
|
||||||
|
onChange={actions.markAll} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderFooter(markedCount) {
|
||||||
|
const { todos } = this.props;
|
||||||
|
const { filter } = this.state;
|
||||||
|
const unmarkedCount = todos.length - markedCount;
|
||||||
|
|
||||||
|
if (todos.length) {
|
||||||
|
return (
|
||||||
|
<Footer markedCount={markedCount}
|
||||||
|
unmarkedCount={unmarkedCount}
|
||||||
|
filter={filter}
|
||||||
|
onClearMarked={::this.handleClearMarked}
|
||||||
|
onShow={::this.handleShow} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
examples/todomvc/components/TodoItem.js
Normal file
68
examples/todomvc/components/TodoItem.js
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
import TodoTextInput from './TodoTextInput';
|
||||||
|
|
||||||
|
export default class TodoItem extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
todo: PropTypes.object.isRequired,
|
||||||
|
editTodo: PropTypes.func.isRequired,
|
||||||
|
deleteTodo: PropTypes.func.isRequired,
|
||||||
|
markTodo: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(props, context) {
|
||||||
|
super(props, context);
|
||||||
|
this.state = {
|
||||||
|
editing: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDoubleClick() {
|
||||||
|
this.setState({ editing: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSave(id, text) {
|
||||||
|
if (text.length === 0) {
|
||||||
|
this.props.deleteTodo(id);
|
||||||
|
} else {
|
||||||
|
this.props.editTodo(id, text);
|
||||||
|
}
|
||||||
|
this.setState({ editing: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {todo, markTodo, deleteTodo} = this.props;
|
||||||
|
|
||||||
|
let element;
|
||||||
|
if (this.state.editing) {
|
||||||
|
element = (
|
||||||
|
<TodoTextInput text={todo.text}
|
||||||
|
editing={this.state.editing}
|
||||||
|
onSave={(text) => this.handleSave(todo.id, text)} />
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
element = (
|
||||||
|
<div className='view'>
|
||||||
|
<input className='toggle'
|
||||||
|
type='checkbox'
|
||||||
|
checked={todo.marked}
|
||||||
|
onChange={() => markTodo(todo.id)} />
|
||||||
|
<label onDoubleClick={::this.handleDoubleClick}>
|
||||||
|
{todo.text}
|
||||||
|
</label>
|
||||||
|
<button className='destroy'
|
||||||
|
onClick={() => deleteTodo(todo.id)} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li className={classnames({
|
||||||
|
completed: todo.marked,
|
||||||
|
editing: this.state.editing
|
||||||
|
})}>
|
||||||
|
{element}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
55
examples/todomvc/components/TodoTextInput.js
Normal file
55
examples/todomvc/components/TodoTextInput.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
|
||||||
|
export default class TodoTextInput extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
onSave: PropTypes.func.isRequired,
|
||||||
|
text: PropTypes.string,
|
||||||
|
placeholder: PropTypes.string,
|
||||||
|
editing: PropTypes.bool,
|
||||||
|
newTodo: PropTypes.bool
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(props, context) {
|
||||||
|
super(props, context);
|
||||||
|
this.state = {
|
||||||
|
text: this.props.text || ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit(e) {
|
||||||
|
const text = e.target.value.trim();
|
||||||
|
if (e.which === 13) {
|
||||||
|
this.props.onSave(text);
|
||||||
|
if (this.props.newTodo) {
|
||||||
|
this.setState({ text: '' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChange(e) {
|
||||||
|
this.setState({ text: e.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBlur(e) {
|
||||||
|
if (!this.props.newTodo) {
|
||||||
|
this.props.onSave(e.target.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<input className={classnames({
|
||||||
|
edit: this.props.editing,
|
||||||
|
'new-todo': this.props.newTodo
|
||||||
|
})}
|
||||||
|
type='text'
|
||||||
|
placeholder={this.props.placeholder}
|
||||||
|
autoFocus='true'
|
||||||
|
value={this.state.text}
|
||||||
|
onBlur={::this.handleBlur}
|
||||||
|
onChange={::this.handleChange}
|
||||||
|
onKeyDown={::this.handleSubmit} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
6
examples/todomvc/constants/ActionTypes.js
Normal file
6
examples/todomvc/constants/ActionTypes.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export const ADD_TODO = 'ADD_TODO';
|
||||||
|
export const DELETE_TODO = 'DELETE_TODO';
|
||||||
|
export const EDIT_TODO = 'EDIT_TODO';
|
||||||
|
export const MARK_TODO = 'MARK_TODO';
|
||||||
|
export const MARK_ALL = 'MARK_ALL';
|
||||||
|
export const CLEAR_MARKED = 'CLEAR_MARKED';
|
3
examples/todomvc/constants/TodoFilters.js
Normal file
3
examples/todomvc/constants/TodoFilters.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const SHOW_ALL = 'show_all';
|
||||||
|
export const SHOW_MARKED = 'show_marked';
|
||||||
|
export const SHOW_UNMARKED = 'show_unmarked';
|
18
examples/todomvc/containers/App.js
Normal file
18
examples/todomvc/containers/App.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import TodoApp from './TodoApp';
|
||||||
|
import { createStore, combineReducers } from 'redux';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import * as reducers from '../reducers';
|
||||||
|
|
||||||
|
const reducer = combineReducers(reducers);
|
||||||
|
const store = createStore(reducer);
|
||||||
|
|
||||||
|
export default class App extends Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Provider store={store}>
|
||||||
|
{() => <TodoApp /> }
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
26
examples/todomvc/containers/TodoApp.js
Normal file
26
examples/todomvc/containers/TodoApp.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { bindActionCreators } from 'redux';
|
||||||
|
import { Connector } from 'react-redux';
|
||||||
|
import Header from '../components/Header';
|
||||||
|
import MainSection from '../components/MainSection';
|
||||||
|
import * as TodoActions from '../actions/TodoActions';
|
||||||
|
|
||||||
|
export default class TodoApp extends Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Connector select={state => ({ todos: state.todos })}>
|
||||||
|
{this.renderChild}
|
||||||
|
</Connector>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderChild({ todos, dispatch }) {
|
||||||
|
const actions = bindActionCreators(TodoActions, dispatch);
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Header addTodo={actions.addTodo} />
|
||||||
|
<MainSection todos={todos} actions={actions} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
10
examples/todomvc/index.html
Normal file
10
examples/todomvc/index.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Redux TodoMVC</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="todoapp" id="root">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script src="/static/bundle.js"></script>
|
||||||
|
</html>
|
8
examples/todomvc/index.js
Normal file
8
examples/todomvc/index.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import React from 'react';
|
||||||
|
import App from './containers/App';
|
||||||
|
import 'todomvc-app-css/index.css';
|
||||||
|
|
||||||
|
React.render(
|
||||||
|
<App />,
|
||||||
|
document.getElementById('root')
|
||||||
|
);
|
47
examples/todomvc/package.json
Normal file
47
examples/todomvc/package.json
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
{
|
||||||
|
"name": "todomvc",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "TodoMVC example for redux",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node server.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/gaearon/redux.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"react",
|
||||||
|
"reactjs",
|
||||||
|
"hot",
|
||||||
|
"reload",
|
||||||
|
"hmr",
|
||||||
|
"live",
|
||||||
|
"edit",
|
||||||
|
"webpack",
|
||||||
|
"flux",
|
||||||
|
"todomvc"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/gaearon/redux/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/gaearon/redux#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"classnames": "^2.1.2",
|
||||||
|
"react": "^0.13.3",
|
||||||
|
"react-redux": "^0.2.1",
|
||||||
|
"redux": "^1.0.0-rc"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-core": "^5.6.18",
|
||||||
|
"babel-loader": "^5.1.4",
|
||||||
|
"node-libs-browser": "^0.5.2",
|
||||||
|
"raw-loader": "^0.5.1",
|
||||||
|
"react-hot-loader": "^1.2.7",
|
||||||
|
"style-loader": "^0.12.3",
|
||||||
|
"todomvc-app-css": "^2.0.1",
|
||||||
|
"webpack": "^1.9.11",
|
||||||
|
"webpack-dev-server": "^1.9.0"
|
||||||
|
}
|
||||||
|
}
|
1
examples/todomvc/reducers/index.js
Normal file
1
examples/todomvc/reducers/index.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export { default as todos } from './todos';
|
50
examples/todomvc/reducers/todos.js
Normal file
50
examples/todomvc/reducers/todos.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import { ADD_TODO, DELETE_TODO, EDIT_TODO, MARK_TODO, MARK_ALL, CLEAR_MARKED } from '../constants/ActionTypes';
|
||||||
|
|
||||||
|
const initialState = [{
|
||||||
|
text: 'Use Redux',
|
||||||
|
marked: false,
|
||||||
|
id: 0
|
||||||
|
}];
|
||||||
|
|
||||||
|
export default function todos(state = initialState, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case ADD_TODO:
|
||||||
|
return [{
|
||||||
|
id: (state.length === 0) ? 0 : state[0].id + 1,
|
||||||
|
marked: false,
|
||||||
|
text: action.text
|
||||||
|
}, ...state];
|
||||||
|
|
||||||
|
case DELETE_TODO:
|
||||||
|
return state.filter(todo =>
|
||||||
|
todo.id !== action.id
|
||||||
|
);
|
||||||
|
|
||||||
|
case EDIT_TODO:
|
||||||
|
return state.map(todo =>
|
||||||
|
todo.id === action.id ?
|
||||||
|
{ ...todo, text: action.text } :
|
||||||
|
todo
|
||||||
|
);
|
||||||
|
|
||||||
|
case MARK_TODO:
|
||||||
|
return state.map(todo =>
|
||||||
|
todo.id === action.id ?
|
||||||
|
{ ...todo, marked: !todo.marked } :
|
||||||
|
todo
|
||||||
|
);
|
||||||
|
|
||||||
|
case MARK_ALL:
|
||||||
|
const areAllMarked = state.every(todo => todo.marked);
|
||||||
|
return state.map(todo => ({
|
||||||
|
...todo,
|
||||||
|
marked: !areAllMarked
|
||||||
|
}));
|
||||||
|
|
||||||
|
case CLEAR_MARKED:
|
||||||
|
return state.filter(todo => todo.marked === false);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
18
examples/todomvc/server.js
Normal file
18
examples/todomvc/server.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
var webpack = require('webpack');
|
||||||
|
var WebpackDevServer = require('webpack-dev-server');
|
||||||
|
var config = require('./webpack.config');
|
||||||
|
|
||||||
|
new WebpackDevServer(webpack(config), {
|
||||||
|
publicPath: config.output.publicPath,
|
||||||
|
hot: true,
|
||||||
|
historyApiFallback: true,
|
||||||
|
stats: {
|
||||||
|
colors: true
|
||||||
|
}
|
||||||
|
}).listen(3000, 'localhost', function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Listening at localhost:3000');
|
||||||
|
});
|
42
examples/todomvc/webpack.config.js
Normal file
42
examples/todomvc/webpack.config.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
var path = require('path');
|
||||||
|
var webpack = require('webpack');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
devtool: 'eval',
|
||||||
|
entry: [
|
||||||
|
'webpack-dev-server/client?http://localhost:3000',
|
||||||
|
'webpack/hot/only-dev-server',
|
||||||
|
'./index'
|
||||||
|
],
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, 'dist'),
|
||||||
|
filename: 'bundle.js',
|
||||||
|
publicPath: '/static/'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
|
new webpack.NoErrorsPlugin()
|
||||||
|
],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'redux-devtools': path.join(__dirname, '..', '..', 'src')
|
||||||
|
},
|
||||||
|
extensions: ['', '.js']
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
loaders: [{
|
||||||
|
test: /\.js$/,
|
||||||
|
loaders: ['react-hot', 'babel'],
|
||||||
|
exclude: /node_modules/,
|
||||||
|
include: __dirname
|
||||||
|
}, {
|
||||||
|
test: /\.js$/,
|
||||||
|
loaders: ['babel'],
|
||||||
|
include: path.join(__dirname, '..', '..', 'src')
|
||||||
|
}, {
|
||||||
|
test: /\.css?$/,
|
||||||
|
loaders: ['style', 'raw'],
|
||||||
|
include: __dirname
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
52
package.json
Normal file
52
package.json
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
{
|
||||||
|
"name": "redux-devtools",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Redux DevTools with hot reloading and time travel",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rimraf lib dist",
|
||||||
|
"build": "babel src --out-dir lib",
|
||||||
|
"build:umd": "webpack src/index.js dist/redux-devtools.js && NODE_ENV=production webpack src/index.js dist/redux-devtools.min.js",
|
||||||
|
"lint": "eslint src test examples",
|
||||||
|
"test": "NODE_ENV=test mocha --compilers js:babel/register --recursive",
|
||||||
|
"test:watch": "NODE_ENV=test mocha --compilers js:babel/register --recursive --watch",
|
||||||
|
"test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive",
|
||||||
|
"prepublish": "npm run lint && npm run test && npm run clean && npm run build && npm run build:umd"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/gaearon/redux-devtools.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"redux",
|
||||||
|
"devtools",
|
||||||
|
"flux",
|
||||||
|
"hot reloading",
|
||||||
|
"time travel",
|
||||||
|
"live edit"
|
||||||
|
],
|
||||||
|
"author": "Dan Abramov <dan.abramov@me.com> (http://github.com/gaearon)",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/gaearon/redux-devtools/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/gaearon/redux-devtools",
|
||||||
|
"devDependencies": {
|
||||||
|
"babel": "^5.5.8",
|
||||||
|
"babel-core": "^5.6.18",
|
||||||
|
"babel-eslint": "^3.1.15",
|
||||||
|
"babel-loader": "^5.1.4",
|
||||||
|
"eslint": "^0.23",
|
||||||
|
"eslint-config-airbnb": "0.0.6",
|
||||||
|
"eslint-plugin-react": "^2.3.0",
|
||||||
|
"expect": "^1.6.0",
|
||||||
|
"isparta": "^3.0.3",
|
||||||
|
"mocha": "^2.2.5",
|
||||||
|
"rimraf": "^2.3.4",
|
||||||
|
"webpack": "^1.9.6",
|
||||||
|
"webpack-dev-server": "^1.8.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"redux": "^1.0.0 || 1.0.0-rc"
|
||||||
|
}
|
||||||
|
}
|
0
src/index.js
Normal file
0
src/index.js
Normal file
0
test/index.spec.js
Normal file
0
test/index.spec.js
Normal file
58
webpack.config.js
Normal file
58
webpack.config.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var webpack = require('webpack');
|
||||||
|
|
||||||
|
var plugins = [
|
||||||
|
new webpack.optimize.OccurenceOrderPlugin(),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
plugins.push(
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
compressor: {
|
||||||
|
screw_ie8: true,
|
||||||
|
warnings: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var reactExternal = {
|
||||||
|
root: 'React',
|
||||||
|
commonjs2: 'react',
|
||||||
|
commonjs: 'react',
|
||||||
|
amd: 'react'
|
||||||
|
};
|
||||||
|
|
||||||
|
var reduxExternal = {
|
||||||
|
root: 'Redux',
|
||||||
|
commonjs2: 'redux',
|
||||||
|
commonjs: 'redux',
|
||||||
|
amd: 'redux'
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
externals: {
|
||||||
|
'react': reactExternal,
|
||||||
|
'react-native': reactExternal,
|
||||||
|
'redux': reduxExternal
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
loaders: [{
|
||||||
|
test: /\.js$/,
|
||||||
|
loaders: ['babel-loader'],
|
||||||
|
exclude: /node_modules/
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
library: 'ReduxDevTools',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
},
|
||||||
|
plugins: plugins,
|
||||||
|
resolve: {
|
||||||
|
extensions: ['', '.js']
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user