An easy way to keep mobx observable persistent and rehydrate.
npm install mobx-keeper
Usage Examples:
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();
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";
}
Keepers values can initialized as single variable, using any JS primitives.
import { keep } from 'mobx-keeper';
const temperature = keep('temperature', 20);
temperature.set(25);
> npm test
> npm run test:watch
> npm run example