-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.tsx
45 lines (41 loc) · 1.21 KB
/
app.tsx
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
import * as ReactDOM from "react-dom";
import * as React from "react";
import * as Counter from "./components/Counter";
import {increment, decrement, incrementIfOdd, incrementAsync, setValue} from "./action";
import {configureStore} from "./store";
import fetch from "isomorphic-fetch";
import * as e6p from "es6-promise";
(e6p as any).polyfill();
const store = configureStore({
state: {
isLoaded: false
},
counter: 0
});
const rootEl = document.getElementById("root");
function render() {
ReactDOM.render(
<Counter state = {store.getState()}
onIncrement = {
() => { store.dispatch(increment()); }
}
onDecrement = {
() => { store.dispatch(decrement()); }
}
incrementIfOdd = {
() => { store.dispatch(incrementIfOdd()); }
}
incrementAsync = {
() => { store.dispatch(incrementAsync()); }
}
/>,
rootEl
);
}
render();
store.subscribe(render);
fetch("/api/counter").then((res) => {
return res.json();
}).then((res) => {
store.dispatch(setValue(res.value));
});