├── .DS_Store
├── .github
└── FUNDING.yml
├── .gitignore
├── .project
├── CASE.md
├── DOM
└── 类名切换.html
├── README.md
├── build
├── JSXTransformer.js
├── angular.js
├── babel.js
├── browser.min.js
├── jquery.js
├── jquery.min.js
├── react-0.13.4.js
├── react-0.13.4.min.js
├── react-0.14.0.js
├── react-dom-0.14.0.js
├── react-dom.js
├── react-with-addons.js
├── react-with-addons.min.js
├── react.js
└── redux.js
├── cms
├── .babelrc
├── app
│ ├── action.js
│ ├── components
│ │ ├── about.jsx
│ │ ├── basic.jsx
│ │ ├── home.jsx
│ │ └── topics.jsx
│ ├── main.js
│ └── reducer.js
├── build
│ ├── bundle.js
│ └── index.html
├── package.json
└── webpack.config.js
├── css
└── weui.css
├── lol
├── .babelrc
├── app
│ ├── action.js
│ ├── components
│ │ ├── about.jsx
│ │ ├── basic.jsx
│ │ ├── home.jsx
│ │ └── topics.jsx
│ ├── main.js
│ └── reducer.js
├── build
│ ├── bundle.js
│ └── index.html
├── package.json
└── webpack.config.js
├── react+webpack+react-router+redux
├── .babelrc
├── app
│ ├── action.js
│ ├── components
│ │ ├── about.jsx
│ │ ├── basic.jsx
│ │ ├── home.jsx
│ │ └── topics.jsx
│ ├── main.js
│ └── reducer.js
├── build
│ ├── bundle.js
│ └── index.html
├── package.json
└── webpack.config.js
├── react+webpack+react-router
├── .babelrc
├── app
│ ├── components
│ │ ├── index
│ │ │ ├── indexA.jsx
│ │ │ ├── indexB.jsx
│ │ │ └── skill.jsx
│ │ ├── productBox.jsx
│ │ └── wscats.jsx
│ └── main.js
├── build
│ ├── bundle.js
│ └── index.html
├── package.json
└── webpack.config.js
├── react+webpack
├── .babelrc
├── app
│ ├── components
│ │ ├── index
│ │ │ ├── indexA.jsx
│ │ │ └── indexB.jsx
│ │ ├── productBox.jsx
│ │ ├── root.jsx
│ │ └── wscats.jsx
│ ├── main.js
│ ├── routes.js
│ └── store.js
├── build
│ ├── bundle.js
│ └── index.html
├── package.json
└── webpack.config.js
├── react-router
└── index.html
├── react
├── .DS_Store
├── component
│ └── src
│ │ ├── app.es5.js
│ │ ├── app.es6.js
│ │ ├── communication
│ │ ├── README.md
│ │ └── communication.html
│ │ ├── define
│ │ ├── README.md
│ │ ├── define.es5.js
│ │ ├── define.es6.js
│ │ ├── define.html
│ │ ├── 函数组件.html
│ │ └── 类组件和props.html
│ │ ├── event
│ │ ├── README.md
│ │ └── event.html
│ │ ├── form
│ │ ├── README.md
│ │ ├── input.html
│ │ └── 表单.html
│ │ ├── lifecycle
│ │ ├── README.md
│ │ ├── lifecycle.html
│ │ └── 生命周期.html
│ │ ├── props
│ │ └── props.html
│ │ ├── render
│ │ ├── README.md
│ │ └── condition-rendering.html
│ │ ├── state
│ │ ├── README.md
│ │ ├── es5-state.html
│ │ ├── es6-state.html
│ │ └── setState.html
│ │ └── style
│ │ └── README.md
├── create-react-app
│ └── README.md
├── js
│ ├── ReactRouter.js
│ ├── ReactRouter.min.js
│ ├── babel.js
│ ├── browser.min.js
│ ├── react-addons-update.js
│ ├── react-dom.js
│ ├── react-router.js
│ ├── react-router.min.js
│ └── react.js
├── jsx
│ ├── 1.helloworld.html
│ ├── 10.v-if.html
│ ├── 11.v-on.html
│ ├── 2.vue.html
│ ├── 3.jsx.html
│ ├── 4.函数式编程.html
│ ├── 5.v-for.html
│ ├── 6.v-show.html
│ ├── 7.v-bind:xxx.html
│ ├── 8.v-html.html
│ ├── 9.xss.html
│ ├── README.md
│ ├── handsome.jpeg
│ └── test.html
├── react-devtool
│ └── README.md
├── reactERP
│ ├── .DS_Store
│ ├── .babelrc
│ ├── dist
│ │ ├── 46661d6d65debc63884004fed6e37e5c.svg
│ │ ├── bundle.js
│ │ ├── fonts
│ │ │ ├── fontawesome-webfont.[md5.hash.hex:7].ttf
│ │ │ └── fontawesome-webfont.[md5.hash.hex:7].woff
│ │ └── src
│ │ │ └── libs
│ │ │ └── font-awesome
│ │ │ └── fonts
│ │ │ ├── fontawesome-webfont.eot
│ │ │ ├── fontawesome-webfont.ttf
│ │ │ ├── fontawesome-webfont.woff
│ │ │ └── fontawesome-webfont.woff2
│ ├── index.html
│ ├── package-lock.json
│ ├── package.json
│ ├── src
│ │ ├── app.js
│ │ ├── components
│ │ │ ├── app
│ │ │ │ └── app.js
│ │ │ ├── cnode
│ │ │ │ ├── cnode.js
│ │ │ │ └── cnode.scss
│ │ │ ├── datagrid
│ │ │ │ ├── datagridaction.js
│ │ │ │ ├── datagridcomponent.js
│ │ │ │ ├── datagridconstants.js
│ │ │ │ └── datagridreducer.js
│ │ │ ├── home
│ │ │ │ ├── header
│ │ │ │ │ ├── header.js
│ │ │ │ │ └── header.scss
│ │ │ │ ├── home.js
│ │ │ │ ├── home.scss
│ │ │ │ └── nav
│ │ │ │ │ ├── nav.js
│ │ │ │ │ └── nav.scss
│ │ │ ├── login
│ │ │ │ ├── login.js
│ │ │ │ └── login.scss
│ │ │ ├── modal
│ │ │ │ ├── modal.css
│ │ │ │ └── modalcomponent.js
│ │ │ └── spinner
│ │ │ │ ├── spinner.js
│ │ │ │ └── spinner.scss
│ │ ├── libs
│ │ │ ├── bootstrap
│ │ │ │ ├── css
│ │ │ │ │ ├── bootstrap-main-responsive.css
│ │ │ │ │ ├── bootstrap-main.css
│ │ │ │ │ ├── bootstrap-theme-light.css
│ │ │ │ │ ├── bootstrap-theme.css
│ │ │ │ │ ├── bootstrap-theme.min.css
│ │ │ │ │ ├── bootstrap.css
│ │ │ │ │ ├── bootstrap.global.css
│ │ │ │ │ ├── bootstrap.min.css
│ │ │ │ │ └── hp.min.css
│ │ │ │ ├── datepicker
│ │ │ │ │ ├── css
│ │ │ │ │ │ └── datepicker.css
│ │ │ │ │ ├── js
│ │ │ │ │ │ └── bootstrap-datepicker.js
│ │ │ │ │ └── less
│ │ │ │ │ │ └── datepicker.less
│ │ │ │ ├── fonts
│ │ │ │ │ ├── glyphicons-halflings-regular.eot
│ │ │ │ │ ├── glyphicons-halflings-regular.svg
│ │ │ │ │ ├── glyphicons-halflings-regular.ttf
│ │ │ │ │ └── glyphicons-halflings-regular.woff
│ │ │ │ └── js
│ │ │ │ │ ├── bootstrap.js
│ │ │ │ │ ├── bootstrap.main.js
│ │ │ │ │ └── bootstrap.min.js
│ │ │ ├── common
│ │ │ │ ├── common.js
│ │ │ │ ├── common.scss
│ │ │ │ └── global.scss
│ │ │ ├── font-awesome
│ │ │ │ ├── css
│ │ │ │ │ ├── font-awesome.css
│ │ │ │ │ └── font-awesome.min.css
│ │ │ │ ├── font-awesome.css
│ │ │ │ ├── font-awesome.min.css
│ │ │ │ ├── fonts
│ │ │ │ │ ├── FontAwesome.otf
│ │ │ │ │ ├── fontawesome-webfont.eot
│ │ │ │ │ ├── fontawesome-webfont.svg
│ │ │ │ │ ├── fontawesome-webfont.ttf
│ │ │ │ │ ├── fontawesome-webfont.woff
│ │ │ │ │ └── fontawesome-webfont.woff2
│ │ │ │ ├── less
│ │ │ │ │ ├── animated.less
│ │ │ │ │ ├── bordered-pulled.less
│ │ │ │ │ ├── core.less
│ │ │ │ │ ├── fixed-width.less
│ │ │ │ │ ├── font-awesome.less
│ │ │ │ │ ├── icons.less
│ │ │ │ │ ├── larger.less
│ │ │ │ │ ├── list.less
│ │ │ │ │ ├── mixins.less
│ │ │ │ │ ├── path.less
│ │ │ │ │ ├── rotated-flipped.less
│ │ │ │ │ ├── stacked.less
│ │ │ │ │ └── variables.less
│ │ │ │ └── scss
│ │ │ │ │ ├── _animated.scss
│ │ │ │ │ ├── _bordered-pulled.scss
│ │ │ │ │ ├── _core.scss
│ │ │ │ │ ├── _fixed-width.scss
│ │ │ │ │ ├── _icons.scss
│ │ │ │ │ ├── _larger.scss
│ │ │ │ │ ├── _list.scss
│ │ │ │ │ ├── _mixins.scss
│ │ │ │ │ ├── _path.scss
│ │ │ │ │ ├── _rotated-flipped.scss
│ │ │ │ │ ├── _stacked.scss
│ │ │ │ │ ├── _variables.scss
│ │ │ │ │ └── font-awesome.scss
│ │ │ └── imgs
│ │ │ │ ├── green.jpg
│ │ │ │ ├── red.jpg
│ │ │ │ └── yellow.jpg
│ │ ├── modules
│ │ │ ├── cp
│ │ │ │ ├── cp.css
│ │ │ │ └── cp.js
│ │ │ ├── login
│ │ │ │ ├── Login.scss
│ │ │ │ ├── LoginAction.js
│ │ │ │ ├── LoginComponent.js
│ │ │ │ ├── LoginConstants.js
│ │ │ │ └── LoginReducer.js
│ │ │ └── order
│ │ │ │ ├── orderAction.js
│ │ │ │ ├── orderComponent.js
│ │ │ │ ├── orderConstant.js
│ │ │ │ └── orderReducer.js
│ │ ├── redux
│ │ │ ├── configStore.js
│ │ │ ├── middleware.js
│ │ │ └── rootReducer.js
│ │ ├── router
│ │ │ └── index.js
│ │ └── utils
│ │ │ ├── HttpClient.js
│ │ │ └── ajaxMiddleware.js
│ └── webpack.config.js
├── redux
│ ├── README.md
│ ├── combineReducers
│ │ └── README.md
│ ├── connetProvider
│ │ └── README.md
│ └── middleware
│ │ ├── .babelrc
│ │ ├── README.md
│ │ ├── dist
│ │ ├── 46661d6d65debc63884004fed6e37e5c.svg
│ │ ├── bundle.js
│ │ └── src
│ │ │ └── libs
│ │ │ └── font-awesome
│ │ │ └── fonts
│ │ │ ├── fontawesome-webfont.eot
│ │ │ ├── fontawesome-webfont.ttf
│ │ │ ├── fontawesome-webfont.woff
│ │ │ └── fontawesome-webfont.woff2
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src
│ │ ├── app.js
│ │ ├── components
│ │ │ ├── cnode
│ │ │ │ └── cnode.js
│ │ │ ├── datagrid
│ │ │ │ ├── datagridaction.js
│ │ │ │ ├── datagridcomponent.js
│ │ │ │ ├── datagridconstants.js
│ │ │ │ └── datagridreducer.js
│ │ │ └── spinner
│ │ │ │ ├── spinner.js
│ │ │ │ └── spinner.scss
│ │ ├── redux
│ │ │ ├── middleware.js
│ │ │ ├── rootReducer.js
│ │ │ └── store.js
│ │ └── utils
│ │ │ └── HttpClient.js
│ │ └── webpack.config.js
├── router
│ ├── README.md
│ ├── index.html
│ └── params.html
├── router4
│ └── README.md
├── summery
│ ├── .DS_Store
│ ├── images
│ │ ├── defect-of-mvc.png
│ │ ├── flux.png
│ │ ├── mobx-flow.png
│ │ ├── mvc-base.png
│ │ ├── redux.png
│ │ └── structure-sharing.png
│ └── summery.md
└── webpack
│ ├── README.md
│ └── what-is-webpack.png
├── redux
├── demo1
│ ├── angular+redux.html
│ ├── index.html
│ └── react+redux.html
├── demo2
│ └── index.html
└── js
│ ├── redux.js
│ └── vue.js
├── 事件委托
└── 事件委托.html
├── 双向数据绑定
├── demo.html
├── 传递函数到函数体.html
└── 遍历列表的事件监听和传参.html
├── 图灵机器人
├── index.html
└── test.json
├── 生命周期
└── index.html
├── 组件
├── 1.weui
│ ├── components
│ │ ├── xheader.jsx
│ │ ├── xpanel.jsx
│ │ └── xsearch.jsx
│ ├── css
│ │ ├── base.css
│ │ └── weui.css
│ ├── index.html
│ └── qqnews.json
├── props传对象.html
├── setState更改状态.html
├── 类式组件和函数组件组合.html
├── 组件添加状态.html
├── 组件的this指向.html
└── 选项卡.html
└── 遍历
└── 遍历.html
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Wscats/react-tutorial/85df1bf51beb4f881a4d4ce3ea612336dc203f97/.DS_Store
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | Thanks
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
19 | -------------------------------------------------------------------------------- /cms/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "babel-core": "^6.24.1", 4 | "babel-loader": "^7.0.0", 5 | "babel-preset-es2015": "^6.24.1", 6 | "babel-preset-react": "^6.24.1", 7 | "less-loader": "^4.0.3", 8 | "react": "^15.5.4", 9 | "react-dom": "^15.5.4", 10 | "react-router-dom": "^4.1.1", 11 | "style-loader": "^0.16.1", 12 | "url-loader": "^0.5.8", 13 | "webpack": "^2.4.1", 14 | "webpack-dev-server": "^2.4.2" 15 | }, 16 | "dependencies": { 17 | "history": "^4.6.1", 18 | "react-bootstrap": "^0.31.0", 19 | "react-redux": "^5.0.5", 20 | "react-router-config": "^1.0.0-beta.3", 21 | "redux": "^3.6.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /cms/webpack.config.js: -------------------------------------------------------------------------------- 1 | //__dirname是node.js中的一个全局变量,它指向当前执行脚本所在的目录 2 | module.exports = { //注意这里是exports不是export 3 | devtool: 'eval-source-map', //生成Source Maps,这里选择eval-source-map 4 | entry: __dirname + "/app/main.js", //唯一入口文件 5 | output: { //输出目录 6 | path: __dirname + "/build", //打包后的js文件存放的地方 7 | filename: 'bundle.js', //打包后的js文件名 8 | }, 9 | module: { 10 | loaders: [{ 11 | test: /\.js[x]?$/, //匹配到js或jsx文件后 使用 babel-loader 来处理 12 | exclude: /node_modules/, //屏蔽不需要处理的文件(文件夹)(可选) 13 | loader: 'babel-loader' 14 | //npm install babel-loader 15 | //npm install babel-core 16 | }, { 17 | test: /\.css$/, 18 | loader: 'style-loader!css-loader' 19 | }, { 20 | test: /\.less$/, 21 | loader: 'style-loader!css-loader!less-loader' 22 | }, { 23 | test: /\.(png|jpg)$/, 24 | loader: 'url-loader?limit=25000' 25 | }] 26 | }, 27 | devServer: { 28 | contentBase: './build', //默认webpack-dev-server会为根文件夹提供本地服务器,如果想为另外一个目录下的文件提供本地服务器,应该在这里设置其所在目录(本例设置到"build"目录) 29 | historyApiFallback: true, //在开发单页应用时非常有用,它依赖于HTML5 history API,如果设置为true,所有的跳转将指向index.html 30 | inline: true, //设置为true,当源文件改变时会自动刷新页面 31 | port: 12345, //设置默认监听端口,如果省略,默认为"8080" 32 | } 33 | }; -------------------------------------------------------------------------------- /lol/.babelrc: -------------------------------------------------------------------------------- 1 | //.babelrc 2 | { 3 | "presets": [ 4 | "react", 5 | "es2015" 6 | ] 7 | } -------------------------------------------------------------------------------- /lol/app/action.js: -------------------------------------------------------------------------------- 1 | export function increaseAction() { 2 | return {type: 'increase'}; 3 | } 4 | 5 | export function multiAction() { 6 | return {type: 'multi'}; 7 | } 8 | -------------------------------------------------------------------------------- /lol/app/components/about.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Jumbotron, 4 | Checkbox, 5 | Radio, 6 | ControlLabel, 7 | FormControl, 8 | Button 9 | } from 'react-bootstrap'; 10 | class About extends React.Component { 11 | render() { 12 | return ( 13 |
This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.
17 |18 | 19 |
20 |22 | ) 23 | } 24 | } 25 | module.exports = About; 26 | -------------------------------------------------------------------------------- /lol/app/components/home.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | import { 3 | Grid, 4 | Row, 5 | Col, 6 | Table, 7 | ButtonToolbar, 8 | Button 9 | } from 'react-bootstrap'; 10 | class ProductBox extends React.Component { 11 | render() { 12 | return ( 13 |
# | 21 |First Name | 22 |Last Name | 23 |Username | 24 |
---|---|---|---|
1 | 29 |Mark | 30 |Otto | 31 |
32 | |
36 |
50 | ) 51 | } 52 | } 53 | module.exports = ProductBox; 54 | -------------------------------------------------------------------------------- /lol/app/components/topics.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {BrowserRouter as Router, Route, Link} from 'react-router-dom' 3 | 4 | import {connect} from 'react-redux'; 5 | 6 | import {increaseAction, multiAction} from '../action.js'; 7 | 8 | const Topic = ({match}) => ( 9 |
12 | ) 13 | class Topics extends React.Component { 14 | render() { 15 | const {value, onIncreaseClick} = this.props; 16 | return ( 17 |
{value}
20 | 21 |
43 | )
44 | }
45 | }
46 |
47 | // Map Redux state to component props
48 | function mapStateToProps(state) {
49 | return {value: state.count}
50 | }
51 |
52 | // Map Redux actions to component props
53 | function mapDispatchToProps(dispatch) {
54 | return {
55 | onIncreaseClick: () => {
56 | //可以触发多个
57 | dispatch(increaseAction())
58 | dispatch(multiAction())
59 | }
60 | }
61 | }
62 |
63 | // Connected Component 让Topics也连接上store
64 | module.exports = connect(mapStateToProps, mapDispatchToProps)(Topics);
65 |
--------------------------------------------------------------------------------
/lol/app/main.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import Basic from "./components/basic.jsx";
4 |
5 | //redux
6 | import {Provider, connect} from 'react-redux';
7 | import {createStore} from 'redux';
8 |
9 | //模块化action,方便在组件中调用
10 | import {increaseAction, multiAction} from './action.js';
11 | //模块化reducer
12 | import counter from './reducer.js';
13 |
14 | // Store
15 | const store = createStore(counter);
16 |
17 | // Action
18 | // const increaseAction = {
19 | // type: 'increase'
20 | // }
21 | //
22 | // const multiAction = {
23 | // type: 'multi'
24 | // }
25 |
26 | // Reducer
27 | // function counter(state = {
28 | // count: 0
29 | // }, action) {
30 | // const count = state.count
31 | // switch (action.type) {
32 | // case 'increase':
33 | // return {
34 | // count: count + 2
35 | // }
36 | // case 'multi':
37 | // return {
38 | // count: count * 2
39 | // }
40 | // default:
41 | // return state
42 | // }
43 | // }
44 |
45 | // 放在Basic入面connect
46 | // // Map Redux state to component props
47 | // function mapStateToProps(state) {
48 | // return {value: state.count}
49 | // }
50 | //
51 | // // Map Redux actions to component props
52 | // function mapDispatchToProps(dispatch) {
53 | // return {
54 | // onIncreaseClick: () => {
55 | // //可以触发多个
56 | // dispatch(increaseAction())
57 | // dispatch(multiAction())
58 | // }
59 | // }
60 | // }
61 |
62 | // Connected Component
63 | //const App = connect(mapStateToProps, mapDispatchToProps)(Basic)
64 |
65 | ReactDOM.render((
66 |
5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
19 | -------------------------------------------------------------------------------- /lol/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "babel-core": "^6.24.1", 4 | "babel-loader": "^7.0.0", 5 | "babel-preset-es2015": "^6.24.1", 6 | "babel-preset-react": "^6.24.1", 7 | "less-loader": "^4.0.3", 8 | "react": "^15.5.4", 9 | "react-dom": "^15.5.4", 10 | "react-router-dom": "^4.1.1", 11 | "style-loader": "^0.16.1", 12 | "url-loader": "^0.5.8", 13 | "webpack": "^2.4.1", 14 | "webpack-dev-server": "^2.4.2" 15 | }, 16 | "dependencies": { 17 | "history": "^4.6.1", 18 | "react-bootstrap": "^0.31.0", 19 | "react-redux": "^5.0.5", 20 | "react-router-config": "^1.0.0-beta.3", 21 | "redux": "^3.6.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lol/webpack.config.js: -------------------------------------------------------------------------------- 1 | //__dirname是node.js中的一个全局变量,它指向当前执行脚本所在的目录 2 | module.exports = { //注意这里是exports不是export 3 | devtool: 'eval-source-map', //生成Source Maps,这里选择eval-source-map 4 | entry: __dirname + "/app/main.js", //唯一入口文件 5 | output: { //输出目录 6 | path: __dirname + "/build", //打包后的js文件存放的地方 7 | filename: 'bundle.js', //打包后的js文件名 8 | }, 9 | module: { 10 | loaders: [{ 11 | test: /\.js[x]?$/, //匹配到js或jsx文件后 使用 babel-loader 来处理 12 | exclude: /node_modules/, //屏蔽不需要处理的文件(文件夹)(可选) 13 | loader: 'babel-loader' 14 | //npm install babel-loader 15 | //npm install babel-core 16 | }, { 17 | test: /\.css$/, 18 | loader: 'style-loader!css-loader' 19 | }, { 20 | test: /\.less$/, 21 | loader: 'style-loader!css-loader!less-loader' 22 | }, { 23 | test: /\.(png|jpg)$/, 24 | loader: 'url-loader?limit=25000' 25 | }] 26 | }, 27 | devServer: { 28 | contentBase: './build', //默认webpack-dev-server会为根文件夹提供本地服务器,如果想为另外一个目录下的文件提供本地服务器,应该在这里设置其所在目录(本例设置到"build"目录) 29 | historyApiFallback: true, //在开发单页应用时非常有用,它依赖于HTML5 history API,如果设置为true,所有的跳转将指向index.html 30 | inline: true, //设置为true,当源文件改变时会自动刷新页面 31 | port: 12345, //设置默认监听端口,如果省略,默认为"8080" 32 | } 33 | }; -------------------------------------------------------------------------------- /react+webpack+react-router+redux/.babelrc: -------------------------------------------------------------------------------- 1 | //.babelrc 2 | { 3 | "presets": [ 4 | "react", 5 | "es2015" 6 | ] 7 | } -------------------------------------------------------------------------------- /react+webpack+react-router+redux/app/action.js: -------------------------------------------------------------------------------- 1 | export function increaseAction() { 2 | return {type: 'increase'}; 3 | } 4 | 5 | export function multiAction() { 6 | return {type: 'multi'}; 7 | } 8 | -------------------------------------------------------------------------------- /react+webpack+react-router+redux/app/components/about.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {ButtonGroup, Button} from 'react-bootstrap'; 3 | class About extends React.Component { 4 | render() { 5 | return ( 6 |
14 | ) 15 | } 16 | } 17 | module.exports = About; 18 | -------------------------------------------------------------------------------- /react+webpack+react-router+redux/app/components/home.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | class ProductBox extends React.Component { 3 | render() { 4 | return( 5 |
6 | ) 7 | } 8 | } 9 | module.exports = ProductBox; -------------------------------------------------------------------------------- /react+webpack+react-router+redux/app/components/topics.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {BrowserRouter as Router, Route, Link} from 'react-router-dom' 3 | 4 | import {connect} from 'react-redux'; 5 | 6 | import {increaseAction, multiAction} from '../action.js'; 7 | 8 | const Topic = ({match}) => ( 9 |
12 | ) 13 | class Topics extends React.Component { 14 | render() { 15 | const {value, onIncreaseClick} = this.props; 16 | return ( 17 |
{value}
20 | 21 |
43 | )
44 | }
45 | }
46 |
47 | // Map Redux state to component props
48 | function mapStateToProps(state) {
49 | return {value: state.count}
50 | }
51 |
52 | // Map Redux actions to component props
53 | function mapDispatchToProps(dispatch) {
54 | return {
55 | onIncreaseClick: () => {
56 | //可以触发多个
57 | dispatch(increaseAction())
58 | dispatch(multiAction())
59 | }
60 | }
61 | }
62 |
63 | // Connected Component 让Topics也连接上store
64 | module.exports = connect(mapStateToProps, mapDispatchToProps)(Topics);
65 |
--------------------------------------------------------------------------------
/react+webpack+react-router+redux/app/main.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import Basic from "./components/basic.jsx";
4 |
5 | //redux
6 | import {Provider, connect} from 'react-redux';
7 | import {createStore} from 'redux';
8 |
9 | //模块化action,方便在组件中调用
10 | import {increaseAction, multiAction} from './action.js';
11 | //模块化reducer
12 | import counter from './reducer.js';
13 |
14 | // Store
15 | const store = createStore(counter);
16 |
17 | // Action
18 | // const increaseAction = {
19 | // type: 'increase'
20 | // }
21 | //
22 | // const multiAction = {
23 | // type: 'multi'
24 | // }
25 |
26 | // Reducer
27 | // function counter(state = {
28 | // count: 0
29 | // }, action) {
30 | // const count = state.count
31 | // switch (action.type) {
32 | // case 'increase':
33 | // return {
34 | // count: count + 2
35 | // }
36 | // case 'multi':
37 | // return {
38 | // count: count * 2
39 | // }
40 | // default:
41 | // return state
42 | // }
43 | // }
44 |
45 | // 放在Basic入面connect
46 | // // Map Redux state to component props
47 | // function mapStateToProps(state) {
48 | // return {value: state.count}
49 | // }
50 | //
51 | // // Map Redux actions to component props
52 | // function mapDispatchToProps(dispatch) {
53 | // return {
54 | // onIncreaseClick: () => {
55 | // //可以触发多个
56 | // dispatch(increaseAction())
57 | // dispatch(multiAction())
58 | // }
59 | // }
60 | // }
61 |
62 | // Connected Component
63 | //const App = connect(mapStateToProps, mapDispatchToProps)(Basic)
64 |
65 | ReactDOM.render((
66 |
5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
-------------------------------------------------------------------------------- /react+webpack+react-router+redux/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "babel-core": "^6.24.1", 4 | "babel-loader": "^7.0.0", 5 | "babel-preset-es2015": "^6.24.1", 6 | "babel-preset-react": "^6.24.1", 7 | "less-loader": "^4.0.3", 8 | "react": "^15.5.4", 9 | "react-dom": "^15.5.4", 10 | "react-router-dom": "^4.1.1", 11 | "style-loader": "^0.16.1", 12 | "url-loader": "^0.5.8", 13 | "webpack": "^2.4.1", 14 | "webpack-dev-server": "^2.4.2" 15 | }, 16 | "dependencies": { 17 | "history": "^4.6.1", 18 | "react-bootstrap": "^0.31.0", 19 | "react-redux": "^5.0.5", 20 | "react-router-config": "^1.0.0-beta.3", 21 | "redux": "^3.6.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /react+webpack+react-router+redux/webpack.config.js: -------------------------------------------------------------------------------- 1 | //__dirname是node.js中的一个全局变量,它指向当前执行脚本所在的目录 2 | module.exports = { //注意这里是exports不是export 3 | devtool: 'eval-source-map', //生成Source Maps,这里选择eval-source-map 4 | entry: __dirname + "/app/main.js", //唯一入口文件 5 | output: { //输出目录 6 | path: __dirname + "/build", //打包后的js文件存放的地方 7 | filename: 'bundle.js', //打包后的js文件名 8 | }, 9 | module: { 10 | loaders: [{ 11 | test: /\.js[x]?$/, //匹配到js或jsx文件后 使用 babel-loader 来处理 12 | exclude: /node_modules/, //屏蔽不需要处理的文件(文件夹)(可选) 13 | loader: 'babel-loader' 14 | //npm install babel-loader 15 | //npm install babel-core 16 | }, { 17 | test: /\.css$/, 18 | loader: 'style-loader!css-loader' 19 | }, { 20 | test: /\.less$/, 21 | loader: 'style-loader!css-loader!less-loader' 22 | }, { 23 | test: /\.(png|jpg)$/, 24 | loader: 'url-loader?limit=25000' 25 | }] 26 | }, 27 | devServer: { 28 | contentBase: './build', //默认webpack-dev-server会为根文件夹提供本地服务器,如果想为另外一个目录下的文件提供本地服务器,应该在这里设置其所在目录(本例设置到"build"目录) 29 | historyApiFallback: true, //在开发单页应用时非常有用,它依赖于HTML5 history API,如果设置为true,所有的跳转将指向index.html 30 | inline: true, //设置为true,当源文件改变时会自动刷新页面 31 | port: 12345, //设置默认监听端口,如果省略,默认为"8080" 32 | } 33 | }; -------------------------------------------------------------------------------- /react+webpack+react-router/.babelrc: -------------------------------------------------------------------------------- 1 | //.babelrc 2 | { 3 | "presets": [ 4 | "react", 5 | "es2015" 6 | ] 7 | } -------------------------------------------------------------------------------- /react+webpack+react-router/app/components/index/indexA.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | //新版本的写法 推荐 3 | class IndexA extends React.Component { 4 | render() { 5 | return( 6 |
7 | ) 8 | } 9 | } 10 | module.exports = IndexA; -------------------------------------------------------------------------------- /react+webpack+react-router/app/components/index/indexB.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | //新版本的写法 推荐 3 | class IndexB extends React.Component { 4 | render() { 5 | return( 6 |
7 | ) 8 | } 9 | } 10 | module.exports = IndexB; -------------------------------------------------------------------------------- /react+webpack+react-router/app/components/index/skill.jsx: -------------------------------------------------------------------------------- 1 | //var React = require('react'); 2 | import React from 'react'; 3 | import PropTypes from 'prop-types'; 4 | //新版本的写法 推荐 5 | class Skill extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | // 设置 initial state 9 | this.state = { 10 | text: props.initialValue || 'Hello Wscats' 11 | }; 12 | // ES6 类中函数必须手动绑定 13 | this.handleChange = this.handleChange.bind(this); 14 | } 15 | componentDidMount() { 16 | console.log(this.props.match) 17 | } 18 | handleChange(event) { 19 | console.log(this) 20 | this.setState({ 21 | text: event.target.value 22 | }); 23 | } 24 | render() { 25 | return( 26 |
{this.state.text}
32 |34 | ) 35 | } 36 | } 37 | Skill.propTypes = { 38 | //定义传入props中的属性各种类型 39 | initialValue: PropTypes.string.isRequired//PropTypes.string 40 | }; 41 | Skill.defaultProps = { 42 | //组件默认的props对象 43 | initialValue: 'Hello Oaoafly' 44 | }; 45 | module.exports = Skill; -------------------------------------------------------------------------------- /react+webpack+react-router/app/components/productBox.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | //旧版本的写法,会有警告 3 | /*var ProductBox = React.createClass({ 4 | render: function() { 5 | return( 6 |
9 | ); 10 | } 11 | });*/ 12 | //新版本的写法 推荐 13 | class ProductBox extends React.Component { 14 | render() { 15 | return( 16 |
17 | ) 18 | } 19 | } 20 | module.exports = ProductBox; -------------------------------------------------------------------------------- /react+webpack+react-router/app/components/wscats.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | var ReactDom = require('react-dom'); 3 | //引入skill组件 4 | var Skill = require('./index/skill.jsx'); 5 | import { 6 | BrowserRouter as Router, 7 | Route, 8 | Link 9 | } from 'react-router-dom' 10 | const Topic = () => ( 11 |
14 | ) 15 | const About = ({match}) => ( 16 |
20 | ) 21 | //新版本的写法 推荐 22 | class Wscats extends React.Component { 23 | render() { 24 | return( 25 |
51 | )
52 | }
53 | }
54 | module.exports = Wscats;
--------------------------------------------------------------------------------
/react+webpack+react-router/app/main.js:
--------------------------------------------------------------------------------
1 | var React = require('react');
2 | var ReactDom = require('react-dom');
3 | //import { Router, Route, Switch } from 'react-router'
4 | import {
5 | BrowserRouter as Router,
6 | Route,
7 | Link
8 | } from 'react-router-dom'
9 |
10 | var AppComponent = require('./components/productBox.jsx');
11 | var Wscats = require('./components/wscats.jsx');
12 | var IndexA = require('./components/index/indexA.jsx');
13 | var IndexB = require('./components/index/indexB.jsx');
14 | /*ReactDom.render(
15 |
25 |
28 |
4 | 5 |
6 | 7 |
-------------------------------------------------------------------------------- /react+webpack+react-router/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "babel-core": "^6.24.1", 4 | "babel-loader": "^7.0.0", 5 | "babel-preset-es2015": "^6.24.1", 6 | "babel-preset-react": "^6.24.1", 7 | "less-loader": "^4.0.3", 8 | "prop-types": "^15.5.10", 9 | "react": "^15.5.4", 10 | "react-dom": "^15.5.4", 11 | "react-router-dom": "^4.1.1", 12 | "style-loader": "^0.16.1", 13 | "url-loader": "^0.5.8", 14 | "webpack": "^2.4.1", 15 | "webpack-dev-server": "^2.4.2" 16 | }, 17 | "dependencies": { 18 | "redux": "^3.6.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /react+webpack+react-router/webpack.config.js: -------------------------------------------------------------------------------- 1 | //__dirname是node.js中的一个全局变量,它指向当前执行脚本所在的目录 2 | module.exports = { //注意这里是exports不是export 3 | devtool: 'eval-source-map', //生成Source Maps,这里选择eval-source-map 4 | entry: __dirname + "/app/main.js", //唯一入口文件 5 | output: { //输出目录 6 | path: __dirname + "/build", //打包后的js文件存放的地方 7 | filename: 'bundle.js', //打包后的js文件名 8 | }, 9 | module: { 10 | loaders: [{ 11 | test: /\.js[x]?$/, //匹配到js或jsx文件后 使用 babel-loader 来处理 12 | exclude: /node_modules/, //屏蔽不需要处理的文件(文件夹)(可选) 13 | loader: 'babel-loader' 14 | //npm install babel-loader 15 | //npm install babel-core 16 | }, { 17 | test: /\.css$/, 18 | loader: 'style-loader!css-loader' 19 | }, { 20 | test: /\.less$/, 21 | loader: 'style-loader!css-loader!less-loader' 22 | }, { 23 | test: /\.(png|jpg)$/, 24 | loader: 'url-loader?limit=25000' 25 | }] 26 | }, 27 | devServer: { 28 | contentBase: './build', //默认webpack-dev-server会为根文件夹提供本地服务器,如果想为另外一个目录下的文件提供本地服务器,应该在这里设置其所在目录(本例设置到"build"目录) 29 | historyApiFallback: true, //在开发单页应用时非常有用,它依赖于HTML5 history API,如果设置为true,所有的跳转将指向index.html 30 | inline: true, //设置为true,当源文件改变时会自动刷新页面 31 | port: 8080, //设置默认监听端口,如果省略,默认为"8080" 32 | } 33 | }; -------------------------------------------------------------------------------- /react+webpack/.babelrc: -------------------------------------------------------------------------------- 1 | //.babelrc 2 | { 3 | "presets": [ 4 | "react", 5 | "es2015" 6 | ] 7 | } -------------------------------------------------------------------------------- /react+webpack/app/components/index/indexA.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | //新版本的写法 推荐 3 | class IndexA extends React.Component { 4 | render() { 5 | return( 6 |
7 | ) 8 | } 9 | } 10 | module.exports = IndexA; -------------------------------------------------------------------------------- /react+webpack/app/components/index/indexB.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | //新版本的写法 推荐 3 | class IndexB extends React.Component { 4 | render() { 5 | return( 6 |
7 | ) 8 | } 9 | } 10 | module.exports = IndexB; -------------------------------------------------------------------------------- /react+webpack/app/components/productBox.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | //旧版本的写法,会有警告 3 | /*var ProductBox = React.createClass({ 4 | render: function() { 5 | return( 6 |
9 | ); 10 | } 11 | });*/ 12 | //新版本的写法 推荐 13 | class ProductBox extends React.Component { 14 | render() { 15 | return( 16 |
17 | ) 18 | } 19 | } 20 | module.exports = ProductBox; -------------------------------------------------------------------------------- /react+webpack/app/components/root.jsx: -------------------------------------------------------------------------------- 1 | //var React = require('react'); 2 | import React, { Component } from 'react'; 3 | import { 4 | BrowserRouter as Router, 5 | Route, 6 | Link 7 | } from 'react-router-dom'; 8 | import { matchRoutes, renderRoutes } from 'react-router-config'; 9 | //新版本的写法 推荐 10 | //class Wscats extends React.Component { 11 | class Wscats extends Component { 12 | render() { 13 | return( 14 |
21 | ) 22 | } 23 | } 24 | module.exports = Wscats; -------------------------------------------------------------------------------- /react+webpack/app/components/wscats.jsx: -------------------------------------------------------------------------------- 1 | //var React = require('react'); 2 | import React, { Component } from 'react'; 3 | var routes = require("../routes.js"); 4 | import { 5 | BrowserRouter as Router, 6 | Route, 7 | Link 8 | } from 'react-router-dom'; 9 | import { matchRoutes, renderRoutes } from 'react-router-config'; 10 | 11 | var IndexA = require('./index/indexA.jsx'); 12 | var IndexB = require('./index/indexB.jsx'); 13 | console.log(routes) 14 | //新版本的写法 推荐 15 | //class Wscats extends React.Component { 16 | class Wscats extends Component { 17 | render() { 18 | return( 19 |
26 | )
27 | }
28 | }
29 | module.exports = Wscats;
--------------------------------------------------------------------------------
/react+webpack/app/main.js:
--------------------------------------------------------------------------------
1 | var React = require('react');
2 | var ReactDom = require('react-dom');
3 | //npm install --save react-router-config
4 | import { matchRoutes, renderRoutes } from 'react-router-config'
5 | import {
6 | BrowserRouter as Router,
7 | Route,
8 | Link
9 | } from 'react-router-dom'
10 |
11 |
12 | var routes = require("./routes.js");
13 | matchRoutes(routes, '/index');
14 | console.log(routes)
15 | //默认路由
16 | const branch = matchRoutes(routes, '/index')
17 | ReactDom.render((
18 |
22 | )*/ 23 | 24 | const routes = [ 25 | { component: Root, 26 | routes: [ 27 | { path: '/', 28 | exact: true, 29 | component: AppComponent 30 | }, 31 | { path: '/index', 32 | component: Wscats, 33 | routes: [ 34 | { path: '/childA', 35 | component: IndexA 36 | }, 37 | { path: '/childB', 38 | component: IndexB 39 | } 40 | ] 41 | } 42 | ] 43 | } 44 | ] 45 | module.exports = routes; -------------------------------------------------------------------------------- /react+webpack/app/store.js: -------------------------------------------------------------------------------- 1 | import { 2 | applyMiddleware, 3 | createStore 4 | } from "redux" 5 | import logger from "redux-logger" 6 | import thunk from "redux-thunk" 7 | import promise from "redux-promise-middleware" 8 | import reducer from "./reducers" 9 | const middleware = applyMiddleware(promise(), thunk, logger()) 10 | export default createStore(reducer, middleware) -------------------------------------------------------------------------------- /react+webpack/build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
6 | 7 |
-------------------------------------------------------------------------------- /react+webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "babel-core": "^6.24.1", 4 | "babel-loader": "^7.0.0", 5 | "babel-preset-es2015": "^6.24.1", 6 | "babel-preset-react": "^6.24.1", 7 | "less-loader": "^4.0.3", 8 | "react": "^15.5.4", 9 | "react-dom": "^15.5.4", 10 | "style-loader": "^0.16.1", 11 | "url-loader": "^0.5.8", 12 | "webpack": "^2.4.1", 13 | "webpack-dev-server": "^2.4.2" 14 | }, 15 | "dependencies": { 16 | "history": "^4.6.1", 17 | "react-router-config": "^1.0.0-beta.3", 18 | "redux": "^3.6.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /react+webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | //__dirname是node.js中的一个全局变量,它指向当前执行脚本所在的目录 2 | module.exports = { //注意这里是exports不是export 3 | devtool: 'eval-source-map', //生成Source Maps,这里选择eval-source-map 4 | entry: __dirname + "/app/main.js", //唯一入口文件 5 | output: { //输出目录 6 | path: __dirname + "/build", //打包后的js文件存放的地方 7 | filename: 'bundle.js', //打包后的js文件名 8 | }, 9 | module: { 10 | loaders: [{ 11 | test: /\.js[x]?$/, //匹配到js或jsx文件后 使用 babel-loader 来处理 12 | exclude: /node_modules/, //屏蔽不需要处理的文件(文件夹)(可选) 13 | loader: 'babel-loader' 14 | //npm install babel-loader 15 | //npm install babel-core 16 | }, { 17 | test: /\.css$/, 18 | loader: 'style-loader!css-loader' 19 | }, { 20 | test: /\.less$/, 21 | loader: 'style-loader!css-loader!less-loader' 22 | }, { 23 | test: /\.(png|jpg)$/, 24 | loader: 'url-loader?limit=25000' 25 | }] 26 | }, 27 | devServer: { 28 | contentBase: './build', //默认webpack-dev-server会为根文件夹提供本地服务器,如果想为另外一个目录下的文件提供本地服务器,应该在这里设置其所在目录(本例设置到"build"目录) 29 | historyApiFallback: true, //在开发单页应用时非常有用,它依赖于HTML5 history API,如果设置为true,所有的跳转将指向index.html 30 | inline: true, //设置为true,当源文件改变时会自动刷新页面 31 | port: 12345, //设置默认监听端口,如果省略,默认为"8080" 32 | } 33 | }; -------------------------------------------------------------------------------- /react-router/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
6 | 7 | 8 | 9 | 10 |
74 |