loop-modules
Version:
Shared modules for the Loop product suite.
49 lines (41 loc) • 1.36 kB
text/typescript
import { Action } from '@ngrx/store';
import { type } from '../utils/type';
const CATEGORY:string = 'LoopSession';
/**
* For each action type in an action group, make a simple
* enum object for all of this group's action types.
*
* The 'type' utility function coerces strings into string
* literal types and runs a simple check to guarantee all
* action types in the application are unique.
*/
export interface ILoopSessionMessageActions {
QUERY: string;
SET_ENTRIES: string;
}
export const ActionTypes: ILoopSessionMessageActions = {
QUERY: type(`[${CATEGORY}] Query`),
SET_ENTRIES: type(`[${CATEGORY}] Set Entries`)
};
/**
* Every action is comprised of at least a type and an optional
* payload. Expressing actions as classes enables powerful
* type checking in reducer functions.
*
* See Discriminated Unions: https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions
*/
export class QueryAction implements Action {
type = ActionTypes.QUERY;
constructor(public payload: any[]) { }
}
export class SetEntriesAction implements Action {
type = ActionTypes.SET_ENTRIES;
constructor(public payload: any[] = []) { }
}
/**
* Export a type alias of all actions in this action group
* so that reducers can easily compose action types
*/
export type Actions
= QueryAction
| SetEntriesAction;