Akita: Allow deep/nested stores

Created on 6 Nov 2019  路  9Comments  路  Source: datorama/akita

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior


Currently you can only create stores in the root level.
E.g.

  • books
  • books.old
  • articles
  • articles.old

Expected behavior


It would be nice to have a way of nesting stores, for better structure and readability
E.g.

  • books

    • old

  • articles

    • old

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?


The motivation would be to have stores more structured and readable. I'm currently using NGRX for every personal project and for work. I would like to switch over to Akita for personal projects and maybe even work, but i currently can't, because this should be an essential feature for state management.

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Most helpful comment

You can create sub stores:

export interface OldBooksState extends EntityState<Book> {}
export interface BooksState extends EntityState<Book> {}

@StoreConfig({ name: 'books' })
export class BooksStore extends EntityStore<BooksState> {

  olds = new EntityStore<OldBooksState>({}, { name: 'old-books' });  

  constructor() {
    super();
  }
}

Same for the Query part.

All 9 comments

I'm not sure what is old. Can you provide the entity shape, please?

It's not supposed to be an entity, my bad. books and articles are stores.

And so are the two old.

What's is old? OldBooksStore?

For example yes, such as BooksStore has a "child" store called OldBooksStore and ArticlesStore has a "child" store called OldArticlesStore.

You can create sub stores:

export interface OldBooksState extends EntityState<Book> {}
export interface BooksState extends EntityState<Book> {}

@StoreConfig({ name: 'books' })
export class BooksStore extends EntityStore<BooksState> {

  olds = new EntityStore<OldBooksState>({}, { name: 'old-books' });  

  constructor() {
    super();
  }
}

Same for the Query part.

There is no concept of a child because it doesn't give any value. You can also inject it:

export interface OldBooksState extends EntityState<Book> {}
export interface BooksState extends EntityState<Book> {}

@StoreConfig({ name: 'old-books' })
export class OldBooksStore extends EntityStore<OldBooksState> {
  constructor() {
    super();
  }
}

export interface BooksState extends EntityState<Book> {}

@StoreConfig({ name: 'books' })
export class BooksStore extends EntityStore<BooksState> {

  constructor(public olds: OldBooksStore) {
    super();
  }
}

Alright, i'll give that a try. I thought that was too simple coming from NGRX :(

Ok, if you need any help, join Akita's Gitter channel :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zvnt picture zvnt  路  6Comments

mikejr83 picture mikejr83  路  6Comments

stherrienaspnet picture stherrienaspnet  路  3Comments

NathanAlcantara picture NathanAlcantara  路  4Comments

brgrz picture brgrz  路  4Comments