mobx-keeper
v0.1.0
Published
A directly and easy way to keep mobx observable persistent.
Downloads
3
Maintainers
Readme
mobx keeper
An easy way to keep mobx observable persistent and rehydrate.
Quickstart
npm install mobx-keeper
Usage Examples:
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