loop-modules
Version:
Shared modules for the Loop product suite.
58 lines (48 loc) • 1.55 kB
text/typescript
import { Action } from '@ngrx/store';
import { type } from '../utils/type';
const CATEGORY:string = 'LoopAssignment';
/**
* 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 ILoopAssignmentActions {
QUERY: string;
SET_ENTRIES: string;
UNREAD: string;
}
export const ActionTypes: ILoopAssignmentActions = {
QUERY: type(`[${CATEGORY}] Query`),
SET_ENTRIES: type(`[${CATEGORY}] Set Entries`),
UNREAD: type(`[${CATEGORY}] Unread`)
};
/**
* 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 class UnreadAction implements Action {
type = ActionTypes.UNREAD;
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
| UnreadAction;