({
initialValue,
promise,
promiseFn,
}: {
initialValue?: Error | T
promise?: Promise<T>
promiseFn?: PromiseFn<T>
})
| 50 | } |
| 51 | |
| 52 | export const init = <T>({ |
| 53 | initialValue, |
| 54 | promise, |
| 55 | promiseFn, |
| 56 | }: { |
| 57 | initialValue?: Error | T |
| 58 | promise?: Promise<T> |
| 59 | promiseFn?: PromiseFn<T> |
| 60 | }) => |
| 61 | ({ |
| 62 | initialValue, |
| 63 | data: initialValue instanceof Error ? undefined : initialValue, |
| 64 | error: initialValue instanceof Error ? initialValue : undefined, |
| 65 | value: initialValue, |
| 66 | startedAt: promise || promiseFn ? new Date() : undefined, |
| 67 | finishedAt: initialValue ? new Date() : undefined, |
| 68 | ...getStatusProps(getInitialStatus(initialValue, promise || promiseFn)), |
| 69 | counter: 0, |
| 70 | promise: neverSettle, |
| 71 | } as ReducerAsyncState<T>) |
| 72 | |
| 73 | export const reducer = <T>(state: ReducerAsyncState<T>, action: AsyncAction<T>) => { |
| 74 | switch (action.type) { |
no test coverage detected