(state: ReducerAsyncState<T>, action: AsyncAction<T>)
| 71 | } as ReducerAsyncState<T>) |
| 72 | |
| 73 | export const reducer = <T>(state: ReducerAsyncState<T>, action: AsyncAction<T>) => { |
| 74 | switch (action.type) { |
| 75 | case ActionTypes.start: |
| 76 | return { |
| 77 | ...state, |
| 78 | startedAt: new Date(), |
| 79 | finishedAt: undefined, |
| 80 | ...getStatusProps(StatusTypes.pending), |
| 81 | counter: action.meta.counter, |
| 82 | promise: action.meta.promise, |
| 83 | } as AsyncPending<T, ReducerBaseState<T>> |
| 84 | case ActionTypes.cancel: |
| 85 | return { |
| 86 | ...state, |
| 87 | startedAt: undefined, |
| 88 | finishedAt: undefined, |
| 89 | ...getStatusProps(getIdleStatus(state.error || state.data)), |
| 90 | counter: action.meta.counter, |
| 91 | promise: action.meta.promise, |
| 92 | } as |
| 93 | | AsyncInitial<T, ReducerBaseState<T>> |
| 94 | | AsyncFulfilled<T, ReducerBaseState<T>> |
| 95 | | AsyncRejected<T, ReducerBaseState<T>> |
| 96 | case ActionTypes.fulfill: |
| 97 | return { |
| 98 | ...state, |
| 99 | data: action.payload, |
| 100 | value: action.payload, |
| 101 | error: undefined, |
| 102 | finishedAt: new Date(), |
| 103 | ...getStatusProps(StatusTypes.fulfilled), |
| 104 | promise: action.meta.promise, |
| 105 | } as AsyncFulfilled<T, ReducerBaseState<T>> |
| 106 | case ActionTypes.reject: |
| 107 | return { |
| 108 | ...state, |
| 109 | error: action.payload, |
| 110 | value: action.payload, |
| 111 | finishedAt: new Date(), |
| 112 | ...getStatusProps(StatusTypes.rejected), |
| 113 | promise: action.meta.promise, |
| 114 | } as AsyncRejected<T, ReducerBaseState<T>> |
| 115 | default: |
| 116 | return state |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | export const dispatchMiddleware = <T>( |
| 121 | dispatch: (action: AsyncAction<T>, ...args: any[]) => void |
no test coverage detected