Last active
March 1, 2019 23:45
-
-
Save alanxone/d3e4135fc75fca22860316ebec0e95a9 to your computer and use it in GitHub Desktop.
NGRX Tutorial - Auth actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NGRX Complete Tutorial Without Pain (Angular6 / RxJS6) | |
// https://medium.com/@andrew.kao/ngrx-complete-tutorial-without-pain-angular6-rxjs6-5511b8cb8dac | |
import { Action } from '@ngrx/store'; | |
// Use 'enum' to be registered as a map later | |
export enum AuthActionTypes { | |
Login = '[Auth] Login', | |
Success = '[Auth] Success', | |
Failed = '[Auth] Failed', | |
Required = '[Auth] Required', | |
} | |
export class Login implements Action { | |
readonly type = AuthActionTypes.Login; | |
// Demonstrate authentication data is defined in a model(interface) | |
// However, any supported objects can be used here, such as a "string" | |
constructor(public payload: Authentication) {} | |
} | |
export class LoginSuccess implements Action { | |
readonly type = AuthActionTypes.Success; | |
// The username will be given as a string | |
// In real scenario, it should be a model as well | |
constructor(public payload: string) {} | |
} | |
export class LoginFailed implements Action { | |
readonly type = AuthActionTypes.Failed; | |
// Failed login, we can use it to do some record or error msg showing | |
constructor(public payload: any) {} | |
} | |
export class LoginRequired implements Action { | |
readonly type = AuthActionTypes.Required; | |
// The action can be without constructor as well | |
} | |
export type AuthActions = | |
| Login | |
| LoginSuccess | |
| LoginFailed | |
| LoginRequired |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment