Skip to content

Instantly share code, notes, and snippets.

@caasi
Created May 9, 2018 13:12
Show Gist options
  • Save caasi/a28b35c210591d9ff8a68d791469c493 to your computer and use it in GitHub Desktop.
Save caasi/a28b35c210591d9ff8a68d791469c493 to your computer and use it in GitHub Desktop.
type Dispatch = any;
type Action<T> = (dispatch: Dispatch) => Promise<T>;
const actionA: (string) => Action<string> =
(foo) => async (dispatch) => {
dispatch('tell redux to do something');
return 'foo';
}
const actionB: (string) => Action<number> =
(bar) => async (dispatch) => {
dispatch('tell redux to do something else');
return 42;
}
const actionC: (string) => Action<number> =
(baz) => async (dispatch) => {
const resultA = await actionA(baz)(dispatch);
dispatch('foo');
const resultB = await actionB(resultA)(dispatch);
dispatch('bar');
return resultB;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment