Skip to content

Commit 6024628

Browse files
author
yunkui.zhou
committed
在服务端集成redux
1 parent c9d60ac commit 6024628

21 files changed

+388
-47
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module.exports = {
135135
"no-template-curly-in-string": "error",
136136
"no-this-before-super": "error",
137137
"no-throw-literal": "error",
138-
"no-trailing-spaces": "error",
138+
"no-trailing-spaces": 1,
139139
"no-undef": "error",
140140
"no-undef-init": "error",
141141
"no-unexpected-multiline": "error",

client/pages/integration/Center/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import React, {Component} from 'react'
88

99
class Center extends Component {
1010
render () {
11-
console.log(this.props)
1211
return (<div>欢迎来到个人中心</div>)
1312
}
1413
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Created by ink on 2018/4/9.
3+
*/
4+
import React from 'react'
5+
import {createDevTools} from 'redux-devtools'
6+
import LogMonitor from 'redux-devtools-log-monitor'
7+
import DockMonitor from 'redux-devtools-dock-monitor'
8+
9+
// createDevTools takes a monitor and produces a DevTools component
10+
const DevTools = createDevTools(
11+
// Monitors are individually adjustable with props.
12+
// Consult their repositories to learn about those props.
13+
// Here, we put LogMonitor inside a DockMonitor.
14+
// Note: DockMonitor is visible by default.
15+
<DockMonitor
16+
toggleVisibilityKey='ctrl-h'
17+
changePositionKey='ctrl-q'
18+
defaultIsVisible={false}>
19+
<LogMonitor theme='tomorrow' />
20+
</DockMonitor>
21+
)
22+
export default DevTools

client/pages/integration/Home/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import * as actions from '../redux/action'
88
class Home extends Component {
99
constructor(options) {
1010
super(options)
11-
console.log(this.props)
11+
console.log(this.props.title)
1212
}
1313
componentDidMount() {
1414
setTimeout(() => {
15-
//this.props.actions.home('我是首页')
15+
this.props.actions.home('我是首页')
1616
//通过action出发路由跳转
17-
this.props.actions.jump('center')
17+
//this.props.actions.jump('center')
1818
}, 2000)
1919
}
2020
render() {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Created by ink on 2018/4/9.
3+
*/
4+
let configureStore
5+
if (process.env.NODE_ENV === 'local') {
6+
configureStore = require('./store.local')
7+
} else {
8+
configureStore = require('./store.prod')
9+
}
10+
module.exports = configureStore
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Created by ink on 2018/4/9.
3+
*/
4+
import {createStore, compose} from 'redux'
5+
import DevTools from '../DevTools/index'
6+
7+
export default function configureStore(reducers, initialState = {}, enhancer) {
8+
const _enhancer = compose(
9+
enhancer,
10+
DevTools.instrument()
11+
)
12+
const store = createStore(reducers, initialState, _enhancer)
13+
return store
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Created by ink on 2018/4/9.
3+
*/
4+
import {createStore} from 'redux'
5+
export default function configureStore(reducers, initialState = {}, enhancer) {
6+
const store = createStore(reducers, initialState, enhancer)
7+
return store
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Created by ink on 2018/4/8.
3+
*/
4+
import {ConnectedRouter} from 'react-router-redux'
5+
import {Provider} from 'react-redux'
6+
import React from 'react'
7+
let ContentEnv
8+
if (process.env.NODE_ENV === 'local') {
9+
ContentEnv = require('./Root.local')
10+
} else {
11+
ContentEnv = require('./Root.prod')
12+
}
13+
const RealContent = ContentEnv.default
14+
const Root = (props) => {
15+
const {store, history, component} = props
16+
return (<Provider store={store}>
17+
<ConnectedRouter history={history}>
18+
<RealContent component={component}/>
19+
</ConnectedRouter>
20+
</Provider>)
21+
}
22+
export {RealContent as Content}
23+
export default Root
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Created by ink on 2018/4/9.
3+
*/
4+
5+
import React, {Fragment} from 'react'
6+
import DevTools from '../DevTools/index'
7+
const Content = (props) => {
8+
const {component: CustomerContent} = props
9+
return (<Fragment>
10+
<CustomerContent/>
11+
<DevTools/>
12+
</Fragment>)
13+
}
14+
export default Content
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Created by ink on 2018/4/9.
3+
*/
4+
import React from 'react'
5+
const Content = (props) => {
6+
const {component: CustomerContent} = props
7+
return <CustomerContent/>
8+
}
9+
10+
export default Content

0 commit comments

Comments
 (0)