Akita: Question: multiple entity store

Created on 11 Aug 2019  路  4Comments  路  Source: datorama/akita

Before my question, I want to mention that you guys did a great job with this package :)

I'm submitting a question

I have a use case where I need 2 lists in the same store, For example on the same page I have 2 different lists, let's say users and markers.
What is the best way to the store the data?
Of course, I can create 2 separate entityStores and entityQuerys but it feels redundant because the 2 lists are related logically and related to the same UI, so it would be more comfortable to have 1 store object.
Another option I thought of, is to create a store object that has 2entityStores as field members, but I am not sure about it.
I tried to look it up in the doc but didn't find information about this use case, So my question is what is the best practice for this scenario?

Thx

Most helpful comment

Thanks. Your second solution is right. You can do something like:

class StoreName {
  users = new EntityStore<UsersState>({}, { name: 'users' });
  markers = new EntityStore<MarkersState>({}, { name: 'markers' });
}

Same goes for the Query.

can you get more specific code for this question. still I can not get how to organize multiple entity store in one store

All 4 comments

Thanks. Your second solution is right. You can do something like:

class StoreName {
  users = new EntityStore<UsersState>({}, { name: 'users' });
  markers = new EntityStore<MarkersState>({}, { name: 'markers' });
}

Same goes for the Query.

Thanks. Your second solution is right. You can do something like:

class StoreName {
  users = new EntityStore<UsersState>({}, { name: 'users' });
  markers = new EntityStore<MarkersState>({}, { name: 'markers' });
}

Same goes for the Query.

can you get more specific code for this question. still I can not get how to organize multiple entity store in one store

Hello team, could you please provide an example of how to use this example? (Store, Service, Query). Thanks!

Looks related to https://netbasal.gitbook.io/akita/general/dynamic-stores :

export class MyService {
  createStore(name: string) {
    const store = new Store(initialState, { name});
    const query = new Query(store);
    return { store, query }
  }  
}
Was this page helpful?
0 / 5 - 0 ratings