import { Injectable } from '@angular/core'; import { EntityState, EntityStore, QueryEntity, StoreConfig } from '@datorama/akita'; import { Game } from '../models/game'; import { GameService } from '../services/game/game.service'; export interface GameState extends EntityState {} @Injectable({ providedIn: 'root' }) @StoreConfig({ idKey: '_id', name: 'games', resettable: true }) export class GameStore extends EntityStore { constructor(private gameService: GameService) { super(); this.gameService.onCreate.subscribe(record => this.add(record)); this.gameService.onDelete.subscribe(record => this.remove(record._id)); this.gameService.onRead.subscribe(records => this.upsertMany(records)); this.gameService.onUpdate.subscribe(record => this.upsert(record._id, record)); } } @Injectable({ providedIn: 'root' }) export class GameQuery extends QueryEntity { constructor(protected store: GameStore) { super(store); } }