import { Auth, User, Err } from '@domain'; import { Action } from '@ngrx/store'; /** * For each action type in an action group, make a simple * enum object for all of this group's action types. */ export enum AuthActionTypes { Login = '[Auth] Login', LoginSuccess = '[Auth] LoginSuccess', LoginFail = '[Auth] LoginFail', Logout = '[Auth] Logout', Register = '[Auth] Register', RegisterSuccess = '[Auth] RegisterSuccess', RegisterFail = '[Auth] RegisterFail', } // export enum LoginActionTypes { // Login = '[Auth] Login', // LoginSuccess = '[Auth] LoginSuccess', // LoginFail = '[Auth] LoginFail', // Logout = '[Auth] Logout' // } // export enum RegisterActionTypes { // Register = '[Register] Register', // RegisterSuccess = '[Register] RegisterSuccess', // RegisterFail = '[Register] RegisterFail', // } /** * Every action is comprised of at least a type and an optional * payload. Expressing actions as classes enables powerful * type checking in reducer functions. */ export class Login implements Action { readonly type = AuthActionTypes.Login; // hint: payload is json, public or private will be a attribute of class constructor(public payload) { } } export class LoginSuccess implements Action { readonly type = AuthActionTypes.LoginSuccess; constructor(public payload: Auth) { } } export class LoginFail implements Action { readonly type = AuthActionTypes.LoginFail; constructor(public payload: Err) { } } export class Logout implements Action { readonly type = AuthActionTypes.Logout; constructor(public payload: Err) { } } /** * Export a type alias of all actions in this action group * so that reducers can easily compose action types */ export type LoginActions = Login | LoginSuccess | LoginFail | Logout; /** * For each action type in an action group, make a simple * enum object for all of this group's action types. */ /** * Every action is comprised of at least a type and an optional * payload. Expressing actions as classes enables powerful * type checking in reducer functions. */ export class Register implements Action { readonly type = AuthActionTypes.Register; constructor(public payload: User) { } } export class RegisterSuccess implements Action { readonly type = AuthActionTypes.RegisterSuccess; constructor(public payload: Auth) { } } export class RegisterFail implements Action { readonly type = AuthActionTypes.RegisterFail; constructor(public payload: Err) { } } /** * Export a type alias of all actions in this action group * so that reducers can easily compose action types */ export type RegisterActions = Register | RegisterSuccess | RegisterFail; export type AuthActions = LoginActions | RegisterActions;