Options
Everywhere you can pass on options object, it can contain the following properties:
Options can be set globally on static MobaseStore.options
property (less priority) and locally by passing them into new MobaseStore(options)
constructor (more priority) and subscribe(options)
(max priority) methods. They will be merged according to priority.
MobaseStore.options.debug = true //set debug mode globally
MobaseStore.options.database = firebase.database() // set db globally
const myStore = new MobaseStore({..., debug: false}) // 'debug' will be overwritten
Mandatory options
database
Should be set to firebase.database()
path :string
Path to firebase node representing you store. For example: '/todos'
fields :object OR model :class
One and only one of this options must be specified. For details please refer to Options: fields vs. model page
Optional
idField :string = 'id'
Key that is used as an id field. Default is 'id'
name :string
Name of this MobaseStore instance which will be kept in global static MobaseStore.stores collection. By default equals to options.path
userId and childId
A path to firebase node is constructed by MobaseStore like this:
path = options.path + '/' + options.userId + '/' + options.childId
Both of them are optional
immediateSubscription :boolean = true
Whether MobaseStore should try to subscribe to to a firebase ref immediately after being created. Default is true
. Otherwise you can subscribe manually with subscribe(options)
method:
const myStore = new MobaseStore({
path: '/todos',
database: firebase.database(),
immediateSubscription: false
}
// later on..
myStore.subscribe({ userId: firebase.auth().currentUser.uid}) // any valid options can be passed
debug :boolean = false
Whether this Mobase store should output debug information. Can be set globally via a static prop: MobaseStore.options.debug
options = {
// this collection name to keep ref in stores[name]
name: null,
// firebase database instance. Mandatory
database: null,
//path to firebase db node. Mandatory
path: null,
//default if field of a record
idField: 'id',
//add userId to path
userId: null,
//add childId to path (path/userId/childId)
childId: null,
//model class to instantiate
model: null,
//fields
fields: null,
//should we subscribe to firebase on store creation
immediateSubscription: true,
//output debug information
debug: MobaseStore.options.debug
}
Hooks (events)
Hooks are options and can be passed via options as well as other methods. Please refer to Hooks (events) page for more details