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

Persist and hydrate MobX-state-tree stores (in < 100 LoC)

License

NotificationsYou must be signed in to change notification settings

agilgur5/mst-persist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

package-jsonreleasescommits

dtdydmdw

NPM

Persist and hydrateMobX-state-tree stores.

Installation

npm i -S mst-persist

Usage

import{types}from'mobx-state-tree'importlocalForagefrom'localForage'import{persist}from'mst-persist'constSomeStore=types.model('Store',{name:'John Doe',age:32})constsomeStore=SomeStore.create()persist('some',someStore,{storage:localForage,// or AsyncStorage in react-native.// default: localStoragejsonify:false// if you use AsyncStorage, this shoud be true// default: truewhitelist:['name']// only these keys will be persisted}).then(()=>console.log('someStore has been hydrated'))

API

persist(key, store, options)

  • arguments

    • keystring The key of your storage engine that you want to persist to.
    • storeMST store The store to be persisted.
    • optionsobject Additional configuration options.
      • storagelocalForage / AsyncStorage / localStoragelocalForage-style storage API. localStorage for Web (default), AsyncStorage for React Native.
      • jsonifybool Enables serialization as JSON (default:true).
      • whitelistArray<string> Only these keys will be persisted (defaults to all keys).
      • blacklistArray<string> These keys will not be persisted (defaults to all keys).
  • returns a void Promise

Examples

None yet, but can take a look atagilgur5/react-native-manga-reader-app which uses it in production.Can view the commit that implements ithere.

How it works

Basically just a small wrapper around MST'sonSnapshot andapplySnapshot.The source code is currently shorter than this README, so take a look under the hood! :)

Credits

Inspiration for parts of the code and API came fromredux-persist,mobx-persist, andthis MST persist PoC gist


[8]ページ先頭

©2009-2025 Movatter.jp