🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

mobx-realm

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobx-realm

Mobx compatibility layer for accessing realm.io database

latest
Source
npmnpm
Version
0.1.3
Version published
Weekly downloads
2
-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

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)

Keywords

mobx

FAQs

Package last updated on 27 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts