loop-modules
Version:
Shared modules for the Loop product suite.
76 lines (62 loc) • 2.07 kB
text/typescript
import { Action } from '@ngrx/store';
import { type } from '../utils/type';
const CATEGORY:string = 'Employee';
/**
* 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 IEmployeeActions {
SUBORDINATES: string;
SET_ENTRIES: string;
TOGGLE_SELECTED: string;
SET_SELECTED: string;
ACTIVE: string;
}
export const ActionTypes: IEmployeeActions = {
SUBORDINATES: type(`[${CATEGORY}] Subordinates`),
SET_ENTRIES: type(`[${CATEGORY}] Set Entries`),
TOGGLE_SELECTED: type(`[${CATEGORY}] Toggle Selected`),
SET_SELECTED: type(`[${CATEGORY}] Set Selected`),
ACTIVE: type(`[${CATEGORY}] Active`)
};
/**
* 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 SubordinatesAction implements Action {
type = ActionTypes.SUBORDINATES;
constructor(public payload: any[]) { }
}
export class SetEntriesAction implements Action {
type = ActionTypes.SET_ENTRIES;
constructor(public payload: any[] = []) { }
}
export class ToggleSelectedAction implements Action {
type = ActionTypes.TOGGLE_SELECTED;
constructor(public payload: any) { }
}
export class SetSelectedAction implements Action {
type = ActionTypes.SET_SELECTED;
constructor(public payload: any[] = []) { }
}
export class ActiveAction implements Action {
type = ActionTypes.ACTIVE;
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
= SubordinatesAction
| SetEntriesAction
| ToggleSelectedAction
| SetSelectedAction
| ActiveAction;