Avoid creating selectors in your components:
Instead, create them in the query:
This makes your components cleaner and the selectors reusable across the application.
Data Storage Types
Store only plain objects in the store, avoid storing
Set. It's more efficient to perform immutable operations (which are required for updating the store) with plain objects rather than with complex ones such as
Moreover, it's harder to serialize this types of objects.
Keep the UI data separated from the model data. Read more about this topic here.
Keep It Simple
Avoid over-engineering. Don't create a separate store for any entity you may have. For example, you might have a list of articles where each article contains a list of comments:
In most cases, there is no need to create a separate entity store for the
comments. Instead use Akita's Array Utils. This will keep your store easier to maintain and use. If you still require a separate store, check out this article for tips on how to combine their data:
- Working with Normalized Data in Akita and Angular
- Introducing One To Many Relationship in Angular & Akita
A question that often comes up is whether to subscribe at the component or the service. Let's examine the two options:
Prefer this option when you need to show the user a success or error message locally in the component:
Otherwise, you can subscribe at the service: