This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@fooxly/persistn

1.0.2 • Public • Published

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

☁️ Installation

using npm

npm install --save @fooxly/persistn

using yarn

yarn add @fooxly/persistn

📎 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;

📐 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)} />
  )
}

📦 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.

📕 API

Note: This part of the documentation is incomplete

📋 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

❤️ Support our projects

You can support us by donating through BuyMeACoffee here.

BuyMeACoffee

Package Sidebar

Install

npm i @fooxly/persistn

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

15.4 kB

Total Files

9

Last publish

Collaborators

  • luchermkens
  • thom1606