Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"registry": "https://registry.npmjs.org/"
},
"main": "lib/index.js",
"typings": "typings/index.d.ts",
"files": [
"lib",
"src"
"src",
"typings"
],
"scripts": {
"build": "babel src -d lib",
Expand Down
38 changes: 38 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as React from "react"

type AsyncChildren<T> = ((state: AsyncState<T>) => React.ReactNode) | React.ReactNode

interface AsyncProps<T> {
promiseFn?: (props: object) => Promise<T>
deferFn?: (...args) => Promise<T>
watch?: any
initialValue?: T
onResolve?: (data: T) => void
onError?: (error: Error) => void
children?: AsyncChildren<T>
}

interface AsyncState<T> {
initialValue?: T
data?: T
error?: Error
isLoading: boolean
startedAt?: Date
finishedAt?: Date
cancel: () => void
run: (...args) => Promise<T>
reload: () => void
setData: (data: T, callback?: () => void) => T
setError: (error: Error, callback?: () => void) => Error
}

declare class Async<T> extends React.Component<AsyncProps<T>, AsyncState<T>> {
static Pending: React.FunctionComponent<{ children?: AsyncChildren<T>; persist?: boolean }>
static Loading: React.FunctionComponent<{ children?: AsyncChildren<T>; initial?: boolean }>
static Resolved: React.FunctionComponent<{ children?: AsyncChildren<T>; persist?: boolean }>
static Rejected: React.FunctionComponent<{ children?: AsyncChildren<T>; persist?: boolean }>
}

declare function createInstance<T>(defaultProps?: AsyncProps<T>): Async<T>

export default createInstance