Using MobaseStore

The simpliest way to use MobaseStore is to create stores with new directly:

import {observable} from 'mobx'
import MobaseStore from 'mobase'

const todoStore = new MobaseStore({
     path: '/todos',
     database: firebase.database(),
     fields: {
          id: observable.ref,
          text: observable.ref
     }
})

Extending MobaseStore

If you want to implement a more advanced logic inside your store, than MobaseStore can be extended:

import {observable} from 'mobx'
import MobaseStore from 'mobase'

class TodoStore extends MobaseStore {

    constructor(myPath) {
        super({
            path: myPath,
            database: firebase.database(),
            fields: {
                id: observable.ref,
                text: observable.ref
            }
        })
    }


    @computed get advancedProp() {
        // this.collection
    }

}

const myStore = new TodoStore('/my_todos')
const ourStore = new TodoStore('/our_todos')

In this case internal collection can be accessed via this._collection or this.collection and naturally you can use all MobaseStore API on extended stores

myStore.values()    // [ {obj}, {obj2}... ]
myStore.toJS()      // { id1: {obj1}, id2: {obj2}... }

results matching ""

    No results matching ""