Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add types definitions for reducer and dispatcher.
  • Loading branch information
ghengeveld committed Apr 30, 2019
1 parent 6caa2b6 commit e33e89f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/index.d.ts
Expand Up @@ -4,6 +4,16 @@ export type AsyncChildren<T> = ((state: AsyncState<T>) => React.ReactNode) | Rea
export type PromiseFn<T> = (props: object, controller: AbortController) => Promise<T>
export type DeferFn<T> = (args: any[], props: object, controller: AbortController) => Promise<T>

interface AbstractAction {
type: string
meta: { counter: number; [meta: string]: any }
}
export type Start = AbstractAction & { type: "start"; payload: () => Promise<void> }
export type Cancel = AbstractAction & { type: "cancel" }
export type Fulfill<T> = AbstractAction & { type: "fulfill"; payload: T }
export type Reject = AbstractAction & { type: "reject"; payload: Error; error: true }
export type AsyncAction<T> = Start | Cancel | Fulfill<T> | Reject

export interface AsyncOptions<T> {
promise?: Promise<T>
promiseFn?: PromiseFn<T>
Expand All @@ -13,6 +23,16 @@ export interface AsyncOptions<T> {
initialValue?: T
onResolve?: (data: T) => void
onReject?: (error: Error) => void
reducer?: (
state: AsyncState<T>,
action: AsyncAction<T>,
internalReducer: (state: AsyncState<T>, action: AsyncAction<T>) => AsyncState<T>
) => AsyncState<T>
dispatcher?: (
action: AsyncAction<T>,
internalDispatch: (action: AsyncAction<T>) => void,
props: object
) => void
[prop: string]: any
}

Expand Down

0 comments on commit e33e89f

Please sign in to comment.