mobx-realm
v0.1.3
Published
Mobx compatibility layer for accessing realm.io database
Downloads
9
Readme
MobxRealm
What is this?
Mobx is a great library to manage your application state. Realm is a great database for react native. This package is just a compatibility layer which enables reactivity of realm objects and collections inside mobx stores with minimum effect to memory footprint performance.
How to use it?
- When declaring your models, set all schema classes to be descendant of MobxRealmModel Like this:
import {MobxRealmModel} from 'mobx-realm';
class Agent extends MobxRealmModel {};
Agent.schema = {
name: 'Agent',
primaryKey: 'number',
properties: {
number: 'int',
firstName: 'string',
lastName: 'string',
}
}
export default Agent;
- Be sure the property is in store is marked as observable and following in your store:
import {observable} from 'mobx';
import {mobxRealmCollection,mobxRealmObject} from 'mobx-realm';
// Let's assume realmDB is initialized somewhere here
class TopSecret {
@observable allAgents = mobxRealmCollection(realmDB.objects('Agent');
@observable bestAgent = mobxRealmObject(realmDB.objectForPrimaryKey(7);
}
- That's actually all. Have fun!
What's missing
- Tests! (hopefully will be added soon, feel free to add PR)