YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.

Home Page:https://syncedstore.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use with mobx class stores?

tomaszferens opened this issue · comments

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!

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!