0.1.3 • Published 5 years ago

mobx-realm v0.1.3

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
5 years ago

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?

  1. 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;
  1. 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); }

3. That's actually all. Have fun!

## What's missing

1. Tests! (hopefully will be added soon, feel free to add PR)
0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago