@randy.tarampi/redux-offline-immutable-config
v1.0.1-1
Published
Provide a configuration for redux-offline to use an immutable root state with redux-persist-immutable
Downloads
31
Readme
redux-offline-immutable-config
Provide a configuration for redux-offline
to use an immutable root state
with redux-persist-immutable
Installation
npm install redux-offline-immutable-config
# or
yarn add redux-offline-immutable-config
Use
Follow redux-offline
base setup instruction at redux-offline
, then apply the following changes.
import { applyMiddleware, createStore, compose } from 'redux';
import { offline } from 'redux-offline';
import defaultConfig from 'redux-offline/lib/defaults';
// replacing redux-offline defaults with immutable* counterparts
import { persist, persistAutoRehydrate, offlineStateLens } from 'redux-offline-immutable-config';
// ...
// example of redux-persist configuration
// see https://github.com/rt2zz/redux-persist#persiststorestore-config-callback
const persistOptions = {};
const persistCallback = () => {
console.log('rehydration completed')
};
const offlineConfig = {
...defaultConfig,
persist,
persistAutoRehydrate,
persistOptions,
persistCallback,
offlineStateLens
};
const preloadedState = fromJS({}); // this is the immutable root state
const store = createStore(
reducer, // your main reducer
preloadedState,
compose(
applyMiddleware(middleware), // your middleware
offline(offlineConfig)
)
);
Customise persistAutoRehydrate
import { persist, persistAutoRehydrate, offlineStateLens } from 'redux-offline-immutable-config';
const autoRehydrateOptions = __DEV__ === true
? {log: true}
: {};
const offlineConfig = {
...defaultConfig,
persist,
persistAutoRehydrate: () => persistAutoRehydrate(autoRehydrateOptions),
persistOptions,
persistCallback,
offlineStateLens
};
// ...
License
MIT