File tree Expand file tree Collapse file tree 3 files changed +25
-12
lines changed Expand file tree Collapse file tree 3 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -18,17 +18,21 @@ const flakify = <T>(f: () => T): Promise<T> =>
18
18
} , 200 + Math . random ( ) * 2000 )
19
19
)
20
20
21
+ type Counter = {
22
+ value : number ,
23
+ }
24
+
21
25
export type Api = {
22
- save ( x : { value : number } ) : Promise < null > ,
23
- load ( ) : ( Promise < { value : number } > ) ,
26
+ save ( x : Counter ) : Promise < null > ,
27
+ load ( ) : ( Promise < Counter > ) ,
24
28
}
25
29
26
30
export const api : Api = {
27
- save : ( counter : { value : number } ) : Promise < null > => flakify ( ( ) => {
31
+ save : ( counter : Counter ) : Promise < null > => flakify ( ( ) => {
28
32
localStorage . setItem ( '__counterValue' , counter . value . toString ( ) )
29
33
return null
30
34
} ) ,
31
- load : ( ) : Promise < { value : number } > => flakify ( ( ) => {
35
+ load : ( ) : Promise < Counter > => flakify ( ( ) => {
32
36
const storedValue = parseInt ( localStorage . getItem ( '__counterValue' ) , 10 )
33
37
return {
34
38
value : storedValue || 0 ,
Original file line number Diff line number Diff line change 1
- import * as React from 'react' // tslint:disable-line
1
+ import * as React from 'react'
2
2
import * as ReactDOM from 'react-dom'
3
3
import * as redux from 'redux'
4
4
import { Provider } from 'react-redux'
@@ -8,18 +8,19 @@ import * as state from './reducers'
8
8
9
9
import { Counter } from './components/counter'
10
10
11
- let store : redux . Store < state . All > = redux . createStore (
11
+ const store : redux . Store < state . All > = redux . createStore (
12
12
state . reducers ,
13
13
{ } as state . All ,
14
14
redux . applyMiddleware ( thunk ) ,
15
15
)
16
16
17
- // Commented out ("let HTML app be HTML app!")
17
+ const Root : React . SFC < { } > = ( ) => (
18
+ < Provider store = { store } >
19
+ < Counter />
20
+ </ Provider >
21
+ )
22
+
18
23
window . addEventListener ( 'DOMContentLoaded' , ( ) => {
19
24
const rootEl = document . getElementById ( 'redux-app-root' )
20
- if ( rootEl ) ReactDOM . render (
21
- < Provider store = { store } >
22
- < Counter />
23
- </ Provider >
24
- , rootEl )
25
+ ReactDOM . render ( < Root /> , rootEl )
25
26
} )
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+
3
+ type RC = React . SFC | React . ComponentClass
4
+
5
+ type HOC = ( C : RC ) => RC
6
+
7
+ export const compose = ( Component : RC , ...hocs : Array < HOC > ) =>
8
+ hocs . reduce ( ( C , hoc ) => hoc ( C ) , Component )
You can’t perform that action at this time.
0 commit comments