ConrabOpto / mst-query

Query library for mobx-state-tree
MIT License
116 stars 8 forks source link

Custom root store #3

Closed k-ode closed 3 years ago

k-ode commented 3 years ago

If mobx-state-tree soon will support lazy loading (current PR), I think it would be really useful it the user could create a custom root store.

createRootStore({
   MessageModel: [types.lazy(() => MessageModel), 'messages']
   UserModel: [types.lazy(() => UserModel), 'users']
});

// which would return something like
const RootStore = types.model({
    messages: types.map(types.lazy(() => MessageModel)),
    users: types.map(types.lazy(() => UserModel))   
}).actions(self => ({
    update(typeName: string, data: any) {
          self[types[typeName]].put(data);
    }
});

This would solve a lot of issues that arise from normalized objects not being part of the same state tree.

k-ode commented 3 years ago

It might be worthwhile to support this anyway. Could make mst-query more useful for projects that don't care about bundle size.