Writing an action
The first building block of state management is that we will write our actions. When writing actions, we have several rules we can follow so that we have good actions in our application:
- Upfront: Writing actions should always come first before developing the features. This gives us an overview of what should be implemented in the application.
- Divide: We should always categorize the actions based on the event source and the associated data.
- Many: Writing more number actions is not an issue. It is more beneficial as more actions create a better overview of the flow of your application.
- Event-Driven: Capture events as you separate the description of an event and how it’s handled.
- Descriptive: Always provide meaningful information using type metadata. This helps debug the state.
Let’s look at an example action that will set the list of blogs in our state:
import { createAction, props } from '@ngrx/store'; export...