-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
69 lines (60 loc) · 1.55 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import reducer from './reducers'
import rootSaga from './sagas'
import Api from './api';
const api = Api.create();
api.getLatestStatus()
.then(data => console.log(data))
.catch(e => console.error(e))
// create the saga middleware
const sagaMiddleware = createSagaMiddleware()
// mount it on the Store
const store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
)
// then run the saga
sagaMiddleware.run(rootSaga)
const Root = () => (
<Counter
value={store.getState()}
onFetchUsers={() => action('FETCH_REQUESTED')}
onIncrement={() => action('INCREMENT')}
onDecrement={() => action('DECREMENT')}
onIncrementAsync={() => action('INCREMENT_ASYNC')} />
)
const action = type => store.dispatch({type})
const Counter = ({ value, onIncrement, onDecrement, onIncrementAsync, onFetchUsers }) =>(
<div>
<button onClick={onIncrementAsync}>
Increment after 1 second
</button>
{' '}
<button onClick={onIncrement}>
Increment
</button>
{' '}
<button onClick={onDecrement}>
Decrement
</button>
<hr />
<div>
Clicked: {value} times
</div>
<hr />
<button onClick={onFetchUsers}>
Fetch users
</button>
</div>
);
// render the application
function render(){
ReactDOM.render(<Root />, document.getElementById('root'));
}
render()
store.subscribe(render)