@randy.tarampi/redux-offline-immutable-config

1.0.1-1 • Public • Published

npm version

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

Readme

Keywords

none

Package Sidebar

Install

npm i @randy.tarampi/redux-offline-immutable-config

Weekly Downloads

5

Version

1.0.1-1

License

MIT

Unpacked Size

9.03 kB

Total Files

15

Last publish

Collaborators

  • randy.tarampi