Dynamic Stores

We can pass the name in the constructor. This gives us the ability to create internal stores on the fly and also provide a store in a component's providers section, enabling us to get a new store instance for each component we create.

export class MyService {
createStore(name: string) {
const store = new Store(initialState, { name});
const query = new Query(store);
return { store, query }
}
}

Or with Angular:

import { guid, Store, StoreConfig } from '@datorama/akita';
// hero.store.ts
export class HeroStore extends Store<HeroState> {
constructor() {
super(initialState, { name: `Hero-${guid()}` }); <========
}
}
// hero.query.ts
export class HeroQuery extends Query<HeroState> {
constructor(protected store: HeroStore) {
super(store);
}
}
@Component({
selector: 'hero',
providers: [HeroService, HeroStore, HeroQuery],
})
export class HeroComponent { }