Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a081bb

Browse files
committed
(docs): add a basic README
- Badges (tbd NPM package tho)- Installation (also tbd NPM package)- Usage and API - same format as mobx-persist and redux-persist, with a bit of copy+paste where exactly the same- How it works encouraging looking under the hood- Credits to redux-persist, mobx-persist, and the gist
1 parent34433a6 commit9a081bb

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

‎README.md‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#mst-persist
2+
3+
[![package-json](https://img.shields.io/github/package-json/v/agilgur5/mst-persist.svg)](https://npmjs.org/package/mst-persist)
4+
[![releases](https://img.shields.io/github/release/agilgur5/mst-persist.svg)](https://github.com/agilgur5/mst-persist/releases)
5+
[![commits](https://img.shields.io/github/commits-since/agilgur5/mst-persist/latest.svg)](https://github.com/agilgur5/mst-persist/commits/master)
6+
7+
[![dt](https://img.shields.io/npm/dt/mst-persist.svg)](https://npmjs.org/package/mst-persist)
8+
[![dy](https://img.shields.io/npm/dy/mst-persist.svg)](https://npmjs.org/package/mst-persist)
9+
[![dm](https://img.shields.io/npm/dm/mst-persist.svg)](https://npmjs.org/package/mst-persist)
10+
[![dw](https://img.shields.io/npm/dw/mst-persist.svg)](https://npmjs.org/package/mst-persist)
11+
12+
[![NPM](https://nodei.co/npm/mst-persist.png?downloads=true&downloadRank=true&stars=true)](https://npmjs.org/package/mst-persist)
13+
14+
Persist and hydrate MobX-state-tree stores.
15+
16+
##Installation
17+
18+
`npm i -S agilgur5/mst-persist`
19+
20+
The`mst-persist` NPM package is not currently owned by me, so please install via GitHub for now.
21+
Will be looking to get ownership of the package[from the owner](https://github.com/pinqy520/mobx-persist/issues/37#issuecomment-361479253) shortly.
22+
23+
##Usage
24+
25+
```javascript
26+
import {types }from'mobx-state-tree'
27+
importlocalForagefrom'localForage'
28+
import {persist }from'mst-persist'
29+
30+
constSomeStore=types.model('Store', {
31+
name:'John Doe',
32+
age:32
33+
})
34+
35+
constsomeStore=SomeStore.create()
36+
37+
persist('some', someStore, {
38+
storage: localForage,// or AsyncStorage in react-native.
39+
// default: localStorage
40+
jsonify:false// if you use AsyncStorage, this shoud be true
41+
// default: true
42+
whitelist: ['name']// only these keys will be persisted
43+
}).then(()=>console.log('someStore has been hydrated'))
44+
45+
```
46+
47+
###API
48+
49+
####`persist(key, store, options)`
50+
51+
- arguments
52+
-**key***string* The key of your storage engine that you want to persist to.
53+
-**store***MST store* The store to be persisted.
54+
-**options***object* Additional configuration options.
55+
-**storage***[localForage](https://github.com/localForage/localForage) / AsyncStorage / localStorage*[localForage](https://github.com/localForage/localForage)-style storage API. localStorage for Web (default), AsyncStorage for React Native.
56+
-**jsonify***bool* Enables serialization as JSON (default:`true`).
57+
-**whitelist***Array\<string\>* Only these keys will be persisted (defaults to all keys).
58+
-**blacklist***Array\<string\>* These keys will not be persisted (defaults to all keys).
59+
60+
- returns a void Promise
61+
62+
##How it works
63+
64+
Basically just a small wrapper around MST's`onSnapshot` and`applySnapshot`.
65+
The source code is currently shorter than this README, so take a look under the hood! :)
66+
67+
##Credits
68+
69+
Inspiration for parts of the code and API came from[`redux-persist`](https://github.com/rt2zz/redux-persist),[`mobx-persist`](https://github.com/pinqy520/mobx-persist), and[this MST persist PoC gist](https://gist.github.com/benjick/c48dd2db575e79c7b0b1043de4556ebc)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp