Convert more async actions to AsyncActionPayload

This commit is contained in:
Travis Ralston 2020-05-13 20:48:49 -06:00
parent 8c72c27da9
commit a3b4c2dfa0
4 changed files with 37 additions and 39 deletions

View file

@ -44,12 +44,11 @@ import { AsyncActionPayload } from "../dispatcher/payloads";
* result is the result of the promise returned by
* `fn`.
*/
export function asyncAction(id: string, fn: () => Promise<any>, pendingFn: () => any): AsyncActionPayload {
export function asyncAction(id: string, fn: () => Promise<any>, pendingFn: () => any | null): AsyncActionPayload {
const helper = (dispatch) => {
dispatch({
action: id + '.pending',
request:
typeof pendingFn === 'function' ? pendingFn() : undefined,
request: typeof pendingFn === 'function' ? pendingFn() : undefined,
});
fn().then((result) => {
dispatch({action: id + '.success', result});