forked from slashhuang/mini-react-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (54 loc) · 1.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Created by slashhuang on 16/5/9.
* mini react-redux
*/
import { createStore } from 'redux';
import React,{Component,PropTypes} from "react";
import {Provider,connect} from "react-redux";
import {render} from "react-dom";
var reducer=function(state,action){
return Object.assign({},state,action);
};
var action=function(){
return {
'type':'dispatching',
'data':['mini','react','redux','worked']
}
};
let store = createStore(reducer,{"hello":"world"});
class Container extends Component{
constructor(props){
super(props);
}
componentDidMount(){
setTimeout(()=>this.props.action(),2000);
}
render(){
return(
<div>
<div>执行动作:{JSON.stringify(this.props.hint)}</div>
<ul>{this.props.data.length?'结果':''}
{this.props.data.map((ele)=>{
return <li>{ele}</li>
})}</ul>
</div>
)
}
};
let IndexContainer= connect((state)=>{
return {
data:state.data||[],
hint:state.type
};
},{action})(Container);
class ModuleContainer extends Component{
constructor(props){
super(props);
}
render(){
return (<Provider store={store}>
<IndexContainer/>
</Provider>)
}
}
render(<ModuleContainer/>,document.getElementById('root'));