@fooxly/persistn v1.0.2
PersistN
Persist and rehydrate the ReactN global state, with support for LoggerN.
A package by Fooxly, based on redux-persist.
: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
import storage from '@fooxly/persistn/storage'
import storage from '@fooxly/persistn/storage/session'
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 rehydratedstateReconciler
option, to define how the rehydrated state object is merged with the initial statepredicate
option, to determine whether or not to persist a change in the global statewhitelist
option, to whitelist certain keys in the state object for persistanceblacklist
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.