Reputation: 375
I've inherited an Angular codebase that contains all the latest tricks and techniques, and I'm having trouble understanding some key things. Normally when I inherit a codebase in any language, I find that I can search it for terms used in one place to see how they are implemented in others and gradually come to an understanding. This doesn't seem to work with NgRx Actions, however. I don't understand the point of code such as
const LOAD = '[Trailer Info Specifics] Load All ';
const load = createAction(LOAD);
export const TrailerInfoActions= {
load
}
When I search the codebase for "Trailer Info Specifics," it only appears in this one file. So what is the point of the name of the action? What digests this information and acts upon it? I've tried watching videos about Angular Reducers/Actions/Effects/Facades and my eyes just glaze over. None of this makes any sense. I come from the world of imperative programming, so I understand there is a learning curve, but this is just so confusing and none of the tutorials I've found are any good. I'm hoping someone can point me in the right direction.
Upvotes: 1
Views: 372
Reputation: 15505
The type
is the only thing that is required to create and send (store.dispatch
) an action. Based on the type, reducers and effects know what to do. They receive all dispatched actions and filter based on this type (that's why it's important to keep action types unique).
It's recommended to follow the "Good Action Hygiene" pattern when declaring types. The template of a type is [Source] Event
, this makes it easier to debug/get to know the application because you can see where the action is dispatched.
The reason why you can't find more references of the type is because we don't want magic strings in an application (these are brittle). Instead, you can look for TrailerInfoActions.load
to know where the action is dispatched and which reducers/effects do something with it. (The type is a static property on the action creator, which is used to filter actions in reducers/effects.)
Upvotes: 2