File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 19
19
"registry" : " https://registry.npmjs.org/"
20
20
},
21
21
"main" : " lib/index.js" ,
22
+ "typings" : " typings/index.d.ts" ,
22
23
"files" : [
23
24
" lib" ,
24
- " src"
25
+ " src" ,
26
+ " typings"
25
27
],
26
28
"scripts" : {
27
29
"build" : " babel src -d lib" ,
Original file line number Diff line number Diff line change
1
+ import * as React from "react"
2
+
3
+ type AsyncChildren < T > = ( ( state : AsyncState < T > ) => React . ReactNode ) | React . ReactNode
4
+
5
+ interface AsyncProps < T > {
6
+ promiseFn ?: ( props : object ) => Promise < T >
7
+ deferFn ?: ( ...args ) => Promise < T >
8
+ watch ?: any
9
+ initialValue ?: T
10
+ onResolve ?: ( data : T ) => void
11
+ onError ?: ( error : Error ) => void
12
+ children ?: AsyncChildren < T >
13
+ }
14
+
15
+ interface AsyncState < T > {
16
+ initialValue ?: T
17
+ data ?: T
18
+ error ?: Error
19
+ isLoading : boolean
20
+ startedAt ?: Date
21
+ finishedAt ?: Date
22
+ cancel : ( ) => void
23
+ run : ( ...args ) => Promise < T >
24
+ reload : ( ) => void
25
+ setData : ( data : T , callback ?: ( ) => void ) => T
26
+ setError : ( error : Error , callback ?: ( ) => void ) => Error
27
+ }
28
+
29
+ declare class Async < T > extends React . Component < AsyncProps < T > , AsyncState < T > > {
30
+ static Pending : React . FunctionComponent < { children ?: AsyncChildren < T > ; persist ?: boolean } >
31
+ static Loading : React . FunctionComponent < { children ?: AsyncChildren < T > ; initial ?: boolean } >
32
+ static Resolved : React . FunctionComponent < { children ?: AsyncChildren < T > ; persist ?: boolean } >
33
+ static Rejected : React . FunctionComponent < { children ?: AsyncChildren < T > ; persist ?: boolean } >
34
+ }
35
+
36
+ declare function createInstance < T > ( defaultProps ?: AsyncProps < T > ) : Async < T >
37
+
38
+ export default createInstance
You can’t perform that action at this time.
0 commit comments