All Projects → pinqy520 → Mobx Persist

pinqy520 / Mobx Persist

Licence: mit
persist mobx stores

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Mobx Persist

mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (-85.71%)
Mutual labels:  mobx, persistence
Mobx Router
A simple router for MobX + React apps
Stars: ✭ 489 (-6.86%)
Mutual labels:  mobx
Formstate
❤️ Form state so simple that you will fall in love 🌹
Stars: ✭ 357 (-32%)
Mutual labels:  mobx
Torat
ToRat is a Remote Administation tool written in Go using Tor as a transport mechanism and RPC for communication
Stars: ✭ 415 (-20.95%)
Mutual labels:  persistence
React Mobx Typescript Boilerplate
A bare minimum frontend boilerplate with React 16.7, Typescript 3.2 and Webpack 4
Stars: ✭ 378 (-28%)
Mutual labels:  mobx
Wadcoms.github.io
WADComs is an interactive cheat sheet, containing a curated list of Unix/Windows offensive tools and their respective commands.
Stars: ✭ 431 (-17.9%)
Mutual labels:  persistence
Token Wizard
(Discontinued) TokenWizard is an DApp to create and manage crowdsale and token contracts using a simple UI
Stars: ✭ 353 (-32.76%)
Mutual labels:  mobx
Mobx React
React bindings for MobX
Stars: ✭ 4,814 (+816.95%)
Mutual labels:  mobx
Only
💐 An easy way to persist and run code block only as many times as necessary on Android.
Stars: ✭ 466 (-11.24%)
Mutual labels:  persistence
Bangumi
💫 An unofficial bgm.tv app client for Android and iOS, built with React Native. 类似专门做ACG的豆瓣, 已适配 iOS/Android, mobile/Pad, light/dark theme, 并加入了很多独有的增强功能
Stars: ✭ 409 (-22.1%)
Mutual labels:  mobx
Bigqueue
Embedded, Fast and Persistent bigqueue implementation
Stars: ✭ 402 (-23.43%)
Mutual labels:  persistence
Starcabinet
🎉 开源的跨平台Github Stars管理分析工具
Stars: ✭ 399 (-24%)
Mutual labels:  mobx
Mobx Angular
MobX connector to Angular
Stars: ✭ 432 (-17.71%)
Mutual labels:  mobx
Ordinary Puzzles App
Mobile and web puzzle game built with React-Native
Stars: ✭ 376 (-28.38%)
Mutual labels:  mobx
Sled
the champagne of beta embedded databases
Stars: ✭ 5,423 (+932.95%)
Mutual labels:  persistence
React home
这是一个react得demo/脚手架项目,包含react16+redux+antd+webpack4+react-router4+sass/less+axios+proxy技术栈
Stars: ✭ 356 (-32.19%)
Mutual labels:  mobx
Mobx Vue
🐉 Vue bindings for MobX
Stars: ✭ 401 (-23.62%)
Mutual labels:  mobx
Rfx Stack
RFX Stack - Universal App
Stars: ✭ 427 (-18.67%)
Mutual labels:  mobx
Web Series
📚 现代 Web 开发语法基础与工程实践,涵盖 Web 开发基础、前端工程化、应用架构、性能与体验优化、混合开发、React 实践、Vue 实践、WebAssembly 等多方面。
Stars: ✭ 666 (+26.86%)
Mutual labels:  mobx
Saint
👁 (s)AINT is a Spyware Generator for Windows systems written in Java. [Discontinued]
Stars: ✭ 522 (-0.57%)
Mutual labels:  persistence

Mobx Persist

npm version

$ npm install mobx-persist --save

Usage

import { observable } from 'mobx'
import { create, persist } from 'mobx-persist'

class SomeItem {
    @persist @observable  name = 'some'
    @persist @observable count = 0
}

class SomeStore {
    @persist('object') @observable         obj = { a: 1, b: 2 }
    @persist('map')    @observable   stringMap = observable.map<string>({})
    @persist('list')   @observable     numList = [1,2,3,4]
    @persist('object', SomeItem) @observable s = new SomeItem
    @persist('map', SomeItem)    @observable m = observable.map<SomeItem>({})
    @persist('list', SomeItem)   @observable l = []
}

const hydrate = create({
    storage: localForage,   // or AsyncStorage in react-native.
                            // default: localStorage
    jsonify: false  // if you use AsyncStorage, here shoud be true
                    // default: true
})

// create the state
export const someStore = new SomeStore()
hydrate('some', someStore).then(() => console.log('someStore has been hydrated'))

without decorators

const data = observable({
    title: 'no decorator',
    someObject: {
        a: 1,
        b: 'b',
    },
    someArray: [{
        c: 1,
        d: 'd'
    }]
})
const schema = {
    title: true,
    someObject: {
        type: 'object',
        schema: {
            a: true,
            b: true
        }
    },
    someArray: {
        type: 'list',
        schema: {
            c: true,
            d: true
        }
    }
}
export const someStore = persist(schema)(data)
hydrate('some', someStore).then(() => console.log('someStore has been hydrated'))

with initial state

const initialState = window.__STATE__.some || {
    obj: { a: 2, b: 1 }
}
export const someStore = new SomeStore()

hydrate('some', someStore, initialState)
    .then(() => console.log('some hydrated'))

re-hydration

const result = hydrate('some', someStore, initialState)
const rehydrate = result.rehydrate
result.then(() => console.log('some hydrated'))

setTimeout(() => {
    rehydrate().then(() => console.log('rehydrated'))
}, 3000)

API

persist(schema)(object)

  • arguments
    • schema string/object Describes the type of data you are planning to persist. Not needed for JS primitive types. Options: 'object' | 'list' | 'map' or a structured schema object.
    • observable any The observable that you are persisting.
  • returns a persistence-enabled version of observable

create(config)

  • arguments
    • config object Describes the storage container you want your data to reside in.
      • storage localForage/AsyncStorage/localStorage localForage-style storage API. localStorage for Web (default), AsyncStorage for React Native
      • jsonify bool Enables serialization as JSON
      • debounce number Debounce interval applied to storage calls (in miliseconds, default 0).
  • returns
    • hydrate function hydrate(key, store, initialState?, customArgs?)
      • key string The key of your datastore that you want to hydrate from your persisted record.
      • store object The store in which that key resides.
      • initialState object Optional initial state the store is seeded with.
      • customArgs object Optional custom arguments that are available during the deserialization process which can be used to pass in e.g. stores to model constructors during deserialization. See https://github.com/mobxjs/serializr#6-use-custom-arguments-to-inject-stores-to-models
      • returns IHydrateResult

interface IHydrateResult

extends Promise

  • methods
    • rehydrate function
      • returns IHydrateResult

Examples

Dependency

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].