YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.
https://syncedstore.org
MIT License
1.71k stars 51 forks source link

How to use with mobx class stores? #62

Closed tomaszferens closed 2 years ago

tomaszferens commented 2 years ago

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!

YousefED commented 2 years ago

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!