
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
mst-persist
Advanced tools
Persist and hydrate MobX-state-tree stores.
npm i -S mst-persist
import { types } from 'mobx-state-tree'
import localForage from 'localForage'
import { persist } from 'mst-persist'
const SomeStore = types.model('Store', {
name: 'John Doe',
age: 32
})
const someStore = SomeStore.create()
persist('some', someStore, {
storage: localForage, // or AsyncStorage in react-native.
// default: localStorage
jsonify: false // if you use AsyncStorage, this shoud be true
// default: true
whitelist: ['name'] // only these keys will be persisted
}).then(() => console.log('someStore has been hydrated'))
persist(key, store, options)
arguments
localForage
.
The default is localStorage
, which has a built-in adaptor to make it support Promises.
For React Native, one may configure AsyncStorage
instead.
redux-persist
's Storage Engines should also be compatible with mst-persist
.true
).returns a void Promise
Node environments are supported so long as you configure a Storage Engine that supports Node, such as redux-persist-node-storage
, redux-persist-cookie-storage
, etc.
This allows you to hydrate your store server-side.
For SSR though, you may not want to hydrate your store server-side, so in that case you can call persist
conditionally:
if (typeof window !== 'undefined') { // window is undefined in Node
persist(...)
}
With this conditional check, your store will only be hydrated client-side.
None yet, but can take a look at agilgur5/react-native-manga-reader-app which uses it in production. Can view the commit that implements it here.
Basically just a small wrapper around MST's onSnapshot
and applySnapshot
.
The source code is currently shorter than this README, so take a look under the hood! :)
Inspiration for parts of the code and API came from redux-persist
, mobx-persist
, and this MST persist PoC gist
FAQs
Persist and hydrate MobX-state-tree stores
We found that mst-persist demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.