The store supports having an
active property, holding the active entity's
id. This can prove to be very useful in cases where you want to interact with the entity that is currently active.
Here's how to set it up:
You can use the store or feature schematics with the flag --withActive="Active" to generate a store which ActiveState.
The Store provides the following methods to update and query the
Set the given entity
id as active:
Update the active entity:
It’s possible to set the
previous entity as
active. For example:
By default, if the active entity is the last one and you select to activate the next entity, it will loop to the beginning and make the first one active. If you want to disable this behavior set the
wrap parameter to
active entity: (don't forget to use the
ActiveState interface in your store's state)
Whether an active entity is set:
Multiple Active Entities
In addition to having one active entity, there are times when we need to manage multiple active entities. Here is how to do it with Akita:
Unlike working with a single active entity, we've added the
MultiActiveState interface and set the initial state of the
active property to an empty array.
You can use the store or feature schematics with the flag --withActive="MultiActive" to generate a store which ActiveState.
In addition to the methods of working with a single active entity, we will also receive the following methods: