Provide a configuration for redux-offline
to use an immutable root state
with redux-persist-immutable
npm install redux-offline-immutable-config
# or
yarn add redux-offline-immutable-config
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)
)
);
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
};
// ...
MIT