├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── demo ├── index.html └── index.jsx ├── index.jsx ├── package.json ├── src ├── components │ ├── CartItem.jsx │ └── Comp.jsx ├── index.jsx └── index.scss └── webpack.config.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "babel-eslint", 4 | "extends": "airbnb", 5 | "rules": { 6 | "constructor-super": "error" 7 | } 8 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ 3 | 4 | npm-debug.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Weiwei SUN 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 | # react-es6-tutorial [![Dependency Status][daviddm-image]][daviddm-url] 2 | 3 | A React tutorial project writing with ES6 and stage-0 features. You can reading the series via: 4 | 5 | - [Part I: Setup the environment](http://wwsun.github.io/posts/react-with-es6-part-1.html) 6 | - [Part II: Props and State](http://wwsun.github.io/posts/react-with-es6-part-2.html) 7 | - [Part III: Function bind](http://wwsun.github.io/posts/react-with-es6-part-3.html) 8 | - [Part IV: HOC and Mixin](http://wwsun.github.io/posts/react-with-es6-part-4.html) 9 | 10 | ## Dependencies 11 | 12 | - node 4.x (prefer LTS) 13 | - npm 3.x (don't use 2.x) 14 | - react 15.x 15 | - [seu](https://github.com/wwsun/seu) 0.x (latest version) 16 | 17 | ## Running 18 | 19 | 1. Clone or download the project 20 | 2. In your local folder, install project dependencies via `npm install` 21 | 3. Run `npm start` to start the [seu](https://github.com/wwsun/seu) service 22 | 4. Open the browser to visit `http://localhost:3000/demo` to check the results 23 | 24 | ## Structure 25 | 26 | ```bash 27 | - demo // display your app 28 | - src 29 | - components // your app components 30 | - index.jsx // your app root 31 | - index.jsx // your app export entry 32 | - webpack.config.js // your custome webpack configs 33 | ``` 34 | 35 | ## Docs 36 | 37 | 1. Compile entry: 38 | 39 | Setup the webpack compile entry by `entry.index` in the `package.json`. 40 | 41 | 2. [SEU](https://github.com/wwsun/seu) is a light weight tool set to help you create, build, watch, lint your React components. 42 | 43 | Using `seu`, you can write react codes with `es6`, `stage-0` features by default. 44 | 45 | 3. If you want to config webpack, such as adding SASS support, you should follow this [doc](http://ant-tool.github.io/webpack-config.html). 46 | 47 | Because [atool-build](https://github.com/ant-tool/atool-build) is depended in the SEU package, therefore, 48 | 49 | ## Read more about React.js: 50 | 51 | - Data processing: 52 | - [The evolution of Flux frameworks](https://medium.com/@dan_abramov/the-evolution-of-flux-frameworks-6c16ad26bb31#.90lamiv5l) 53 | - Getting to know [Redux](https://github.com/rackt/redux) | [Video](https://egghead.io/series/getting-started-with-redux) 54 | - Keeping your state flat: [normalizr](https://github.com/gaearon/normalizr) 55 | - Trying [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch) to communicate with APIs 56 | - Immutable state: 57 | - [Immutable objects](https://en.wikipedia.org/wiki/Immutable_object) 58 | - Trying [immutable.js](https://facebook.github.io/immutable-js/) 59 | - Reding Lee Byron's [Immutable data and react](https://www.youtube.com/watch?v=I7IdS-PbEgI) 60 | - Router: 61 | - Trying [react-router](https://github.com/rackt/react-router) 62 | - In redux, you can use [redux-simple-router](https://github.com/rackt/redux-simple-router) 63 | - Code splitting, lazy loading: using webpack 64 | - Getting to know: [HTTP/2 multiplexed](https://http2.github.io/faq/#why-is-http2-multiplexed) 65 | - Combining with [chunk hashing](https://christianalfoni.github.io/react-webpack-cookbook/Optimizing-caching.html) you can also optimize your cache hit ratio after code changes. 66 | - Reading Ryan Florence's [Welcome to Future of Web Application Delivery](https://medium.com/@ryanflorence/welcome-to-future-of-web-application-delivery-9750b7564d9f#.vuf3e1nqi) 67 | - Components: 68 | - Using JSX: [JSX looks like an abomination - but it's good for you](https://medium.com/javascript-scene/jsx-looks-like-an-abomination-1c1ec351a918#.ca28nvee6) 69 | - Using ES6 Class, extends `React.Component` 70 | - Using [High Order Components](http://jamesknelson.com/structuring-react-applications-higher-order-components/) to replace mixins 71 | - [Mixin is dead](https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750) 72 | - Checking `propTypes` 73 | - Tests 74 | - Component testing: trying AirBnB's [enzyme](https://github.com/airbnb/enzyme) 75 | - Assertion library: [chai-enyzime](https://github.com/producthunt/chai-enzyme) 76 | - Redux testing: async actions testing [redux-mock-store](https://www.npmjs.com/package/redux-mock-store) 77 | - [Redux testing in depth](http://rackt.org/redux/docs/recipes/WritingTests.html) 78 | - Bundle 79 | - Reading: [Reduce your bundle.js file size by doing this one thing](https://lacke.mn/reduce-your-bundle-js-file-size/) 80 | - Getting to know more about [Webpack](https://christianalfoni.github.io/react-webpack-cookbook) 81 | - Component-level hot reload: [react-transform-boilerplate](https://github.com/gaearon/react-transform-boilerplate) 82 | - Linters 83 | - Force linters: [pre-push](https://www.npmjs.com/package/pre-push) or [pre-commit](https://www.npmjs.com/package/pre-commit) 84 | - Javascript Standard Style with [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) 85 | - [The Elm Architecutre](https://github.com/evancz/elm-architecture-tutorial/) 86 | 87 | ## References: 88 | 89 | 1. [React.js Best Practices for 2016](https://blog.risingstack.com/react-js-best-practices-for-2016/) 90 | | [CN](http://insights.thoughtworkers.org/react-js-best-practices-for-2016/) 91 | 92 | 93 | [daviddm-image]: https://david-dm.org/wwsun/react-es6-tutorial.svg?theme=shields.io 94 | [daviddm-url]: https://david-dm.org/wwsun/react-res6-tutorial -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |Quantity: {this.state.qty}
63 | 64 |65 | 66 | 67 |
68 | 69 |Price per item: ${price}
70 | 71 |