How to use with mobx class stores?
tomaszferens opened this issue · comments
Tomasz Ferens commented
Is it allowed to pass mobx store instance into syncedStore
fn? My store has a bunch of methods and I am worried this will not work. In this case, how should I integrate with mobx? Separate actions/getters somehow?
Example store:
class TodoStore {
todos = [];
get completedTodosCount() {
return this.todos.filter(
todo => todo.completed === true
).length;
}
addTodo(task) {
this.todos.push({
task: task,
completed: false,
assignee: null
});
}
}
const todoStore = new TodoStore();
Thanks!
Yousef commented
Hi @tomaszferens !
You could make todos a MobX Computed that returns the right property from the SyncedStore store.
i.e.:
get todos() {
return mySyncedStore.todos;
}
That should bridge both stores and work all fine!