Entity Store Usage
Let’s say we have the following
We have an
EntityStore which holds a collection of articles. Each
article holds an array of
comments. Akita provides helper methods that take care of the grunt work.
The first parameter is typed, so you’ll get intelligent code completion suggesting only keys that are typed as
Each function takes an optional
idKey which defaults to
Adds a value to an array if it doesn't exist yet or removes it if already present. Objects are compared by identity by default. You can override it by providing a custom compare function.
Akita provides two common comparators for
byKey(key: string) compare function.
Toggling an array of objects:
Toggling an array of primitive values:
We can use the same helpers for properties belongs to a
Store. For example:
That takes care of the CRUD operations, but we also have some good stuff added to the
Query; Akita now provides a special operator to query specific items from a collection -
The added advantage is that these observables will only fire if one of the items in the resulting collection has been modified, via an update, add or delete operation.