Skip to content

A directly and easy way to keep mobx observable persistent.

License

Notifications You must be signed in to change notification settings

gplopes/mobx-keeper

Repository files navigation

mobx-keeper

mobx keeper

An easy way to keep mobx observable persistent and rehydrate.

npm version Build Status PRs Welcome npm downloads

Quickstart

npm install mobx-keeper

Usage Examples:

  1. Basic Usage
  2. Decorator Usage
  3. Variable Usage

Basic Usage

Basic usage can be created inside an ES6+ class or a function.

import { createKeeper } from 'mobx-keeper';


// ES6+ Class

class Store {
  constructor() {
    createKeeper(this, { storeItem: 'lorem ipsum' });
  }
}

// Function

function Store() {
  createKeeper(this, { storeItem: 'lorem ispum' });
}
const myStore = new Store();

Decorator Usage

If you are using Decorators Transformer with Babel or another compile you can wrap variables with keep and it will return a mobx observable.

import { keep } from 'mobx-keeper';


// @Decorator

class Store {
  @keep storeItem = "lorem ispum";
}

Variable Usage

Keepers values can initialized as single variable, using any JS primitives.

import { keep } from 'mobx-keeper';

const temperature = keep('temperature', 20);
temperature.set(25);

PR, Comments & feedback are welcome :)

Run test

> npm test
> npm run test:watch

Run playground

A playground with a more visual example
> npm run example

Built With Mobx

forthebadge

Releases

No releases published

Packages

No packages published