Skip to content

Instantly share code, notes, and snippets.

@alanxone
Last active March 1, 2019 23:45
Show Gist options
  • Save alanxone/d3e4135fc75fca22860316ebec0e95a9 to your computer and use it in GitHub Desktop.
Save alanxone/d3e4135fc75fca22860316ebec0e95a9 to your computer and use it in GitHub Desktop.
NGRX Tutorial - Auth actions
// 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