1.0.2 • Published 5 years ago

@fooxly/persistn v1.0.2

Weekly downloads
3
License
MIT
Repository
gitlab
Last release
5 years ago

PersistN

Persist and rehydrate the ReactN global state, with support for LoggerN.

A package by Fooxly, based on redux-persist.

pipeline status coverage report PRs Welcome npm version npm bundle size

:cloud: Installation

using npm

npm install --save @fooxly/persistn

using yarn

yarn add @fooxly/persistn

:paperclip: Importing

ES6 and up

The module uses an ES6 style export statement, simply use import to load the module.

import PersistN from '@fooxly/persistn';

ES5

If you're using an ES5 require statement to load the module, please add default. Look here for more details.

Note: The remaining documentation is written in ES6.

var PersistN = require('@fooxly/persistn').default;

:triangular_ruler: Usage

Note: This part of the documentation is incomplete

Basic Usage

PersistN configuration replaces the initial setGlobal() call for simplicity.

Example File: index.js

import setGlobal from './persist'

setGlobal({
  foo: 'bar'
})

// ... your code

Check Storage Engines for more information about the storage import.

Example File: persist.js

import reactn from 'reactn'
import PersistN from '@fooxly/persistn'
import storage from '@fooxly/persistn/storage'

const persistConfig = {
  key: 'root',
  storage
}

export default initial => {
  PersistN(persistConfig, reactn, initial)
}

Use Actions

The following actions are available:

  • Purge: Reset the state to the initial state
  • Pause: Pause the persistance of the state (also paused on reload)
  • Resume: Resume the persistance of the state

Example File: App.js

import { useGlobal } from 'reactn'
import { PERSIST_KEY, PURGE } from '@fooxly/persistn'

export default () => {
  const persist = useGlobal(PERSIST_KEY)

  return (
    <button onClick={() => persist(PURGE)} />
  )
}

:package: Storage Engines

  • localStorage

    import storage from '@fooxly/persistn/storage'

  • sessionStorage

    import storage from '@fooxly/persistn/storage/session'

  • AsyncStorage

    import AsyncStorage from '@react-native-community/async-storage'

Check here for more suggestions.

:closed_book: API

Note: This part of the documentation is incomplete

:clipboard: To-do

  • Add actionTransformer export for better LoggerN support
  • transforms option, customize the state object that gets persisted and rehydrated
  • stateReconciler option, to define how the rehydrated state object is merged with the initial state
  • predicate option, to determine whether or not to persist a change in the global state
  • whitelist option, to whitelist certain keys in the state object for persistance
  • blacklist option, to blacklist certain keys in the state object from persistance, this also improves support for RequestN

:heart: Support our projects

You can support us by donating through BuyMeACoffee here.

BuyMeACoffee

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago