From 2c7c3232e3e716b1ca31d161f1599970b80690ff Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 14 Jul 2015 22:46:44 +0300 Subject: [PATCH] Add project skeleton (no DevTools yet) --- .babelrc | 4 + .eslintignore | 4 + .eslintrc | 19 +++++ .gitignore | 6 ++ .npmignore | 6 ++ .travis.yml | 3 + CHANGELOG.md | 4 + CODE_OF_CONDUCT.md | 14 ++++ LICENSE.md | 21 +++++ README.md | 4 + examples/counter/.babelrc | 3 + examples/counter/actions/CounterActions.js | 33 ++++++++ examples/counter/components/Counter.js | 25 ++++++ examples/counter/constants/ActionTypes.js | 2 + examples/counter/containers/App.js | 20 +++++ examples/counter/containers/CounterApp.js | 18 +++++ examples/counter/index.html | 10 +++ examples/counter/index.js | 7 ++ examples/counter/package.json | 32 ++++++++ examples/counter/reducers/counter.js | 12 +++ examples/counter/reducers/index.js | 1 + examples/counter/server.js | 18 +++++ examples/counter/webpack.config.js | 38 +++++++++ examples/todomvc/.babelrc | 3 + examples/todomvc/actions/TodoActions.js | 42 ++++++++++ examples/todomvc/components/Footer.js | 71 +++++++++++++++++ examples/todomvc/components/Header.js | 25 ++++++ examples/todomvc/components/MainSection.js | 84 ++++++++++++++++++++ examples/todomvc/components/TodoItem.js | 68 ++++++++++++++++ examples/todomvc/components/TodoTextInput.js | 55 +++++++++++++ examples/todomvc/constants/ActionTypes.js | 6 ++ examples/todomvc/constants/TodoFilters.js | 3 + examples/todomvc/containers/App.js | 18 +++++ examples/todomvc/containers/TodoApp.js | 26 ++++++ examples/todomvc/index.html | 10 +++ examples/todomvc/index.js | 8 ++ examples/todomvc/package.json | 47 +++++++++++ examples/todomvc/reducers/index.js | 1 + examples/todomvc/reducers/todos.js | 50 ++++++++++++ examples/todomvc/server.js | 18 +++++ examples/todomvc/webpack.config.js | 42 ++++++++++ package.json | 52 ++++++++++++ src/index.js | 0 test/index.spec.js | 0 webpack.config.js | 58 ++++++++++++++ 45 files changed, 991 insertions(+) create mode 100644 .babelrc create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 CODE_OF_CONDUCT.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 examples/counter/.babelrc create mode 100644 examples/counter/actions/CounterActions.js create mode 100644 examples/counter/components/Counter.js create mode 100644 examples/counter/constants/ActionTypes.js create mode 100644 examples/counter/containers/App.js create mode 100644 examples/counter/containers/CounterApp.js create mode 100644 examples/counter/index.html create mode 100644 examples/counter/index.js create mode 100644 examples/counter/package.json create mode 100644 examples/counter/reducers/counter.js create mode 100644 examples/counter/reducers/index.js create mode 100644 examples/counter/server.js create mode 100644 examples/counter/webpack.config.js create mode 100644 examples/todomvc/.babelrc create mode 100644 examples/todomvc/actions/TodoActions.js create mode 100644 examples/todomvc/components/Footer.js create mode 100644 examples/todomvc/components/Header.js create mode 100644 examples/todomvc/components/MainSection.js create mode 100644 examples/todomvc/components/TodoItem.js create mode 100644 examples/todomvc/components/TodoTextInput.js create mode 100644 examples/todomvc/constants/ActionTypes.js create mode 100644 examples/todomvc/constants/TodoFilters.js create mode 100644 examples/todomvc/containers/App.js create mode 100644 examples/todomvc/containers/TodoApp.js create mode 100644 examples/todomvc/index.html create mode 100644 examples/todomvc/index.js create mode 100644 examples/todomvc/package.json create mode 100644 examples/todomvc/reducers/index.js create mode 100644 examples/todomvc/reducers/todos.js create mode 100644 examples/todomvc/server.js create mode 100644 examples/todomvc/webpack.config.js create mode 100644 package.json create mode 100644 src/index.js create mode 100644 test/index.spec.js create mode 100644 webpack.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..15d27ad9 --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "stage": 0, + "loose": "all" +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..0d38857e --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +lib +**/node_modules +**/webpack.config.js +examples/**/server.js \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..04a5a3af --- /dev/null +++ b/.eslintrc @@ -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" + ] +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a6d1c49e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +node_modules +*.log +.DS_Store +dist +lib +coverage diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..c21cda52 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +.DS_Store +*.log +src +test +examples +coverage diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..c42701ff --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "iojs" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..bdf25ac6 --- /dev/null +++ b/CHANGELOG.md @@ -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/). diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..a0fd0d6b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -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/) + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..af2353dc --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 00000000..05d4c567 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Redux DevTools +========================= + +Haha. README coming. diff --git a/examples/counter/.babelrc b/examples/counter/.babelrc new file mode 100644 index 00000000..b0b9a96e --- /dev/null +++ b/examples/counter/.babelrc @@ -0,0 +1,3 @@ +{ + "stage": 0 +} diff --git a/examples/counter/actions/CounterActions.js b/examples/counter/actions/CounterActions.js new file mode 100644 index 00000000..9ddaa835 --- /dev/null +++ b/examples/counter/actions/CounterActions.js @@ -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); + }; +} diff --git a/examples/counter/components/Counter.js b/examples/counter/components/Counter.js new file mode 100644 index 00000000..c58dc316 --- /dev/null +++ b/examples/counter/components/Counter.js @@ -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 ( +

+ Clicked: {counter} times + {' '} + + {' '} + + {' '} + +

+ ); + } +} diff --git a/examples/counter/constants/ActionTypes.js b/examples/counter/constants/ActionTypes.js new file mode 100644 index 00000000..c01b8a98 --- /dev/null +++ b/examples/counter/constants/ActionTypes.js @@ -0,0 +1,2 @@ +export const INCREMENT_COUNTER = 'INCREMENT_COUNTER'; +export const DECREMENT_COUNTER = 'DECREMENT_COUNTER'; diff --git a/examples/counter/containers/App.js b/examples/counter/containers/App.js new file mode 100644 index 00000000..970195d2 --- /dev/null +++ b/examples/counter/containers/App.js @@ -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 ( + + {() => } + + ); + } +} diff --git a/examples/counter/containers/CounterApp.js b/examples/counter/containers/CounterApp.js new file mode 100644 index 00000000..f0813c89 --- /dev/null +++ b/examples/counter/containers/CounterApp.js @@ -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 ( + + ); + } +} diff --git a/examples/counter/index.html b/examples/counter/index.html new file mode 100644 index 00000000..696101a5 --- /dev/null +++ b/examples/counter/index.html @@ -0,0 +1,10 @@ + + + Redux Counter Example + + +
+
+ + + diff --git a/examples/counter/index.js b/examples/counter/index.js new file mode 100644 index 00000000..2a188641 --- /dev/null +++ b/examples/counter/index.js @@ -0,0 +1,7 @@ +import React from 'react'; +import App from './containers/App'; + +React.render( + , + document.getElementById('root') +); diff --git a/examples/counter/package.json b/examples/counter/package.json new file mode 100644 index 00000000..2c03ff3a --- /dev/null +++ b/examples/counter/package.json @@ -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" + } +} diff --git a/examples/counter/reducers/counter.js b/examples/counter/reducers/counter.js new file mode 100644 index 00000000..94b6dfa0 --- /dev/null +++ b/examples/counter/reducers/counter.js @@ -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; + } +} diff --git a/examples/counter/reducers/index.js b/examples/counter/reducers/index.js new file mode 100644 index 00000000..d6a1f1d1 --- /dev/null +++ b/examples/counter/reducers/index.js @@ -0,0 +1 @@ +export { default as counter } from './counter'; diff --git a/examples/counter/server.js b/examples/counter/server.js new file mode 100644 index 00000000..ff92aa06 --- /dev/null +++ b/examples/counter/server.js @@ -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'); +}); diff --git a/examples/counter/webpack.config.js b/examples/counter/webpack.config.js new file mode 100644 index 00000000..85335866 --- /dev/null +++ b/examples/counter/webpack.config.js @@ -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') + }] + } +}; diff --git a/examples/todomvc/.babelrc b/examples/todomvc/.babelrc new file mode 100644 index 00000000..b0b9a96e --- /dev/null +++ b/examples/todomvc/.babelrc @@ -0,0 +1,3 @@ +{ + "stage": 0 +} diff --git a/examples/todomvc/actions/TodoActions.js b/examples/todomvc/actions/TodoActions.js new file mode 100644 index 00000000..f8cfb289 --- /dev/null +++ b/examples/todomvc/actions/TodoActions.js @@ -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 + }; +} diff --git a/examples/todomvc/components/Footer.js b/examples/todomvc/components/Footer.js new file mode 100644 index 00000000..b8feaa92 --- /dev/null +++ b/examples/todomvc/components/Footer.js @@ -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 ( +
+ {this.renderTodoCount()} +
    + {[SHOW_ALL, SHOW_UNMARKED, SHOW_MARKED].map(filter => +
  • + {this.renderFilterLink(filter)} +
  • + )} +
+ {this.renderClearButton()} +
+ ); + } + + renderTodoCount() { + const { unmarkedCount } = this.props; + const itemWord = unmarkedCount === 1 ? 'item' : 'items'; + + return ( + + {unmarkedCount || 'No'} {itemWord} left + + ); + } + + renderFilterLink(filter) { + const title = FILTER_TITLES[filter]; + const { filter: selectedFilter, onShow } = this.props; + + return ( + onShow(filter)}> + {title} + + ); + } + + renderClearButton() { + const { markedCount, onClearMarked } = this.props; + if (markedCount > 0) { + return ( + + ); + } + } +} diff --git a/examples/todomvc/components/Header.js b/examples/todomvc/components/Header.js new file mode 100644 index 00000000..203a7157 --- /dev/null +++ b/examples/todomvc/components/Header.js @@ -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 ( +
+

todos

+ +
+ ); + } +} diff --git a/examples/todomvc/components/MainSection.js b/examples/todomvc/components/MainSection.js new file mode 100644 index 00000000..42ee1856 --- /dev/null +++ b/examples/todomvc/components/MainSection.js @@ -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 ( +
+ {this.renderToggleAll(markedCount)} +
    + {filteredTodos.map(todo => + + )} +
+ {this.renderFooter(markedCount)} +
+ ); + } + + renderToggleAll(markedCount) { + const { todos, actions } = this.props; + if (todos.length > 0) { + return ( + + ); + } + } + + renderFooter(markedCount) { + const { todos } = this.props; + const { filter } = this.state; + const unmarkedCount = todos.length - markedCount; + + if (todos.length) { + return ( +