NGXS/Store Action naming reuseability

Viewed 846

In the official documentation, it is suggested that we put inside the brackets [] where the Action comes from:

Names should contain three parts:

A context as to where the command came from, [User API], [Product Page], [Dashboard Page].

A verb describing what we want to do with the entity.

The entity we are acting upon, User, Card, Project.

Examples:

[User API] GetUser

[Product Page] AddItemToCart

[Dashboard Page] ArchiveProject

However, what if there's 2 different locations where we're calling the Action?

In my Angular app, I have the following Action:

export class ClearActiveItem {
  static readonly type = '[Items Page] ClearActiveItem';
}

How do I name this so I emphasize that ClearActiveItem can be dispatched from another place other than Items Page?

1 Answers

Actions should capture events, not commands.

Therefore you should create two actions, one for each location where the event happens.

A great video on the topic is Good Action Hygiene by Mike Ryan It's for NgRx, but the same concepts apply to NGXS.

Related