Generating actions

Do this by typing the following:

ng generate action jedis

It will generate an actions file for us called jedi.actions.ts with the following content:

// jedis.actions.tsimport { Action } from '@ngrx/store';export enum JedisActionTypes {  JedisAction = '[Jedis] Action'}export class Jedis implements Action {  readonly type = JediActionTypes.JediAction;}export type JediActions = Jedi;

The preceding code gives us nice scaffolded files with some nice defaults and it creates a enum type that we can use in conjunction with reducers and selectors. Looking at the preceding code, we realize that we need to extend JedisActionTypes if we want things such as ADD, CREATE, and other CRUD operations.

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.