https://github.com/gplopes/mobx-keeper
A directly and easy way to keep mobx observable persistent.
https://github.com/gplopes/mobx-keeper
javascript mobx mobx-decorators mobx-react persistent persistent-storage
Last synced: about 2 months ago
JSON representation
A directly and easy way to keep mobx observable persistent.
- Host: GitHub
- URL: https://github.com/gplopes/mobx-keeper
- Owner: gplopes
- License: mit
- Created: 2017-12-31T00:00:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-27T07:06:45.000Z (about 7 years ago)
- Last Synced: 2025-04-14T21:12:15.913Z (about 2 months ago)
- Topics: javascript, mobx, mobx-decorators, mobx-react, persistent, persistent-storage
- Language: JavaScript
- Size: 157 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# mobx keeper
An easy way to keep mobx observable persistent and rehydrate.
[](https://badge.fury.io/js/mobx-keeper)
[](https://travis-ci.org/gplopes/mobx-keeper)
[](http://makeapullrequest.com)
[](https://www.npmjs.com/package/mobx-keeper)## Quickstart
`npm install mobx-keeper`Usage Examples:
1. [Basic Usage](#basic-usage)
2. [Decorator Usage](#decorator-usage)
3. [Variable Usage](#variable-usage)#### Basic Usage
Basic usage can be created inside an ES6+ class or a function.
```js
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](https://babeljs.io/docs/plugins/transform-decorators/) with Babel or another compile you can wrap variables with **keep** and it will return a mobx observable.
```js
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.```js
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](https://mobx.js.org/)[](https://forthebadge.com)