API

CRUD Operations

  • set(entities: E[] | HashMap<E> | Entities)

Replace current collection with provided collection, and reset the active entity.

this.store.set([Entity, Entity]);
this.store.set({1: Entity, 2: Entity});
this.store.set({ ids: [1], entities: { 1: {} } });

Pay attention that if you pass an object, Akita doesn't guarantee the order of the data received.

  • add(entities: E[] | E, options: { prepend: boolean })

Add an entity or entities to the store:

this.store.add([Entity, Entity]);
this.store.add(Entity);
this.store.add([Entity, Entity], { prepend: true });
this.store.add(Entity, { prepend: true });
  • update(id: ID | ID[] | null | predicateFn, newStateFn: ((entity: Readonly<E>) => Partial<E>) | Partial<E>)

Update an entity or entities in the store:

this.store.update(3, {
name: 'New Name'
});
this.store.update((e) => e.name === 'Netanel', {
name: 'New Name'
});
this.store.update(3, entity => {
return {
config: {
...entity.filter,
date
}
}
});
this.store.update([1,2,3], {
name: 'New Name'
});
/** Update All */
this.store.update(null, {
name: 'New Name'
});
  • remove(ids?: ID | ID[] | ((entity: Readonly<E>) => boolean)

Remove one or more entities from the store:

this.store.remove(5);
this.store.remove([1,2,3]);
this.store.remove(e => e.name === 'Netanel');
this.store.remove();
  • upsert(id: IDS, entity: Entity, options)

Insert or update an entity.

this.todosStore.upsert(id, {
isOpen: true
});
// when working with a class
this.todosStore.upsert(id, {
isOpen: true
}, { baseClass: Todo });
  • upsertMany([entity, entity], options)

this.todosStore.upsertMany([entity, entity]);
this.todosStore.upsertMany([entity, entity], { baseClass: Todo });
  • replace

Replace an entity (except the id)

store.replace(5, newEntity)
store.replace([5,1,3], newEntity)
  • move(fromIndex: number, toIndex: number)

store.move(3, 2);
  • setLoading(loading = false)

Update the store's loading state. The initial value is set to true and is switched to false when you call store.set(). This can come in handy for indicating loading:

this.store.setLoading(true);
  • setError(error)

Update the store's error state:

this.store.setError('Example of error');
  • destroy()

Destroy the store.