@@ -88,7 +88,7 @@ see [running on CodeSandbox][cs].
8888
8989## API
9090
91- This package exports a grand total of three functions.
91+ This package exports a grand total of four functions.
9292
9393A lot of the generics for these functions can be inferred (see above example).
9494The typings below provided are optimized for readability.
@@ -155,6 +155,39 @@ The `reduceReducers` function takes an array of reducer functions and an
155155optional initial state value and returns a single reducer which runs all of the
156156input reducers in sequence.
157157
158+ ### ` createAsyncActions<T, A extends any[], ...>(type: string, startPayloadCreator, successPayloadCreator, failPayloadCreator) `
159+
160+ Oftentimes when working with sagas, thunks, or some other asynchronous,
161+ side-effecting middleware you need to create three actions which are named
162+ similarly. This is a convenience function which calls ` createAction ` three
163+ times for you. Consider the following example:
164+
165+ ``` ts
166+ import { noop } from ' lodash' ;
167+ import { createAsyncActions } from ' redux-ts-utils' ;
168+
169+ type User = { name: string };
170+
171+ export const [
172+ requestUsers,
173+ requestUsersSuccess,
174+ requestUsersFailure,
175+ ] = createAsyncActions (' REQUEST_USERS' , noop , (users : User []) => users );
176+
177+ requestUsers (); // returns action of type `REQUEST_USERS`
178+ requestUsersSuccess ([{ name: ' knpwrs' }]); // returns action of type `REQUEST_USERS/SUCCESS`
179+ requestUsersError (); // returns action of type `REQUEST_USERS/ERROR`
180+ ```
181+
182+ The first argument is the action/triad name, and the second through third
183+ (optional) arguments are payload creators for the initial action, the success
184+ action, and the error action, respectively. ` noop ` is imported from lodash in
185+ order to be explicit that in this case the payload for ` requestUsers ` is
186+ ` void ` . You can just as easily use ` () => {} ` inline. The action creators infer
187+ their payload types from the supplied payload creators. See [ the
188+ implementation] ( ./src/create-async-actions.ts ) for complete type information.
189+
190+
158191## Design Philosophy
159192
160193### A Strong Emphasis on Type Safety
0 commit comments