-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
40 lines (30 loc) · 953 Bytes
/
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
import ReactDOM from 'react-dom';
import { bindActionCreators } from 'redux';
import counter from './components/counter';
import configureStore from './store/configureStore';
import * as CounterActions from './actions/counter';
function handleEvent(store, events) {
const actions = bindActionCreators(CounterActions, store.dispatch);
events.increment$.subscribe(() => {
actions.increment();
});
events.decrement$.subscribe(() => {
actions.decrement();
});
events.incrementIfOdd$.subscribe(() => {
if (store.getState().counter % 2 !== 0) {
actions.increment();
}
});
events
.incrementAsync$
.delay(1000)
.subscribe(() => {
actions.increment();
});
}
const store = configureStore();
const counter$ = store.state$.map(state => state.counter);
const { element: Counter, events } = counter(counter$);
handleEvent(store, events);
ReactDOM.render(Counter, document.getElementById('root'));