UNPKG

1.84 kBTypeScriptView Raw
1import { ActionCreatorProps, Creator } from './models';
2import { ActionGroup, ActionGroupConfig } from './action_group_creator_models';
3/**
4 * @description
5 * A function that creates a group of action creators with the same source.
6 *
7 * @param config An object that contains a source and dictionary of events.
8 * An event is a key-value pair of an event name and event props.
9 * @returns A dictionary of action creators.
10 * The name of each action creator is created by camel casing the event name.
11 * The type of each action is created using the "[Source] Event Name" pattern.
12 *
13 * @usageNotes
14 *
15 * ```ts
16 * const authApiActions = createActionGroup({
17 * source: 'Auth API',
18 * events: {
19 * // defining events with payload using the `props` function
20 * 'Login Success': props<{ userId: number; token: string }>(),
21 * 'Login Failure': props<{ error: string }>(),
22 *
23 * // defining an event without payload using the `emptyProps` function
24 * 'Logout Success': emptyProps(),
25 *
26 * // defining an event with payload using the props factory
27 * 'Logout Failure': (error: Error) => ({ error }),
28 * },
29 * });
30 *
31 * // action type: "[Auth API] Login Success"
32 * authApiActions.loginSuccess({ userId: 10, token: 'ngrx' });
33 *
34 * // action type: "[Auth API] Login Failure"
35 * authApiActions.loginFailure({ error: 'Login Failure!' });
36 *
37 * // action type: "[Auth API] Logout Success"
38 * authApiActions.logoutSuccess();
39 *
40 * // action type: "[Auth API] Logout Failure";
41 * authApiActions.logoutFailure(new Error('Logout Failure!'));
42 * ```
43 */
44export declare function createActionGroup<Source extends string, Events extends Record<string, ActionCreatorProps<unknown> | Creator>>(config: ActionGroupConfig<Source, Events>): ActionGroup<Source, Events>;
45export declare function emptyProps(): ActionCreatorProps<void>;