Skip to content

Commit e33e89f

Browse files
committed
Add types definitions for reducer and dispatcher.
1 parent 6caa2b6 commit e33e89f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/index.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ export type AsyncChildren<T> = ((state: AsyncState<T>) => React.ReactNode) | Rea
44
export type PromiseFn<T> = (props: object, controller: AbortController) => Promise<T>
55
export type DeferFn<T> = (args: any[], props: object, controller: AbortController) => Promise<T>
66

7+
interface AbstractAction {
8+
type: string
9+
meta: { counter: number; [meta: string]: any }
10+
}
11+
export type Start = AbstractAction & { type: "start"; payload: () => Promise<void> }
12+
export type Cancel = AbstractAction & { type: "cancel" }
13+
export type Fulfill<T> = AbstractAction & { type: "fulfill"; payload: T }
14+
export type Reject = AbstractAction & { type: "reject"; payload: Error; error: true }
15+
export type AsyncAction<T> = Start | Cancel | Fulfill<T> | Reject
16+
717
export interface AsyncOptions<T> {
818
promise?: Promise<T>
919
promiseFn?: PromiseFn<T>
@@ -13,6 +23,16 @@ export interface AsyncOptions<T> {
1323
initialValue?: T
1424
onResolve?: (data: T) => void
1525
onReject?: (error: Error) => void
26+
reducer?: (
27+
state: AsyncState<T>,
28+
action: AsyncAction<T>,
29+
internalReducer: (state: AsyncState<T>, action: AsyncAction<T>) => AsyncState<T>
30+
) => AsyncState<T>
31+
dispatcher?: (
32+
action: AsyncAction<T>,
33+
internalDispatch: (action: AsyncAction<T>) => void,
34+
props: object
35+
) => void
1636
[prop: string]: any
1737
}
1838

0 commit comments

Comments
 (0)