While reviewing a typescript file within an Angular ngrx project titled collection.ts
, I came across the declaration of enum constants.
import { Action } from '@ngrx/store';
import { Book } from '../models/book';
export enum CollectionActionTypes {
AddBook = '[Collection] Add Book',
AddBookSuccess = '[Collection] Add Book Success',
AddBookFail = '[Collection] Add Book Fail',
RemoveBook = '[Collection] Remove Book',
RemoveBookSuccess = '[Collection] Remove Book Success',
RemoveBookFail = '[Collection] Remove Book Fail',
Load = '[Collection] Load',
LoadSuccess = '[Collection] Load Success',
LoadFail = '[Collection] Load Fail',
}
/**
* Actions for Adding Books to Collection
*/
export class AddBook implements Action {
readonly type = CollectionActionTypes.AddBook;
constructor(public payload: Book) {}
}
...
export type CollectionActions =
| AddBook
| AddBookSuccess
...
| LoadFail;
It seems that providing values to enum constants is standard practice, but there's confusion about the significance of [Collection]
attached to each constant. Does this extra notation affect the value or convey something else? Any insights on this concept would be greatly appreciated.