redux-replicate-localforage

3.0.2 • Public • Published

redux-replicate-localforage

npm version npm downloads

Replicator for redux-replicate designed to locally persist the state of redux stores using localforage.

Table of contents

  1. Installation
  2. Usage
  3. Example using react-redux-provide
  4. Example using compose
  5. Debouncing

Installation

npm install redux-replicate-localforage --save

Usage

Use with redux-replicate.

Example using react-redux-provide

// src/replication.js
 
import localforage from 'redux-replicate-localforage';
import { theme } from './providers/index';
 
theme.replication = {
  reducerKeys: ['themeName'],
  replicator: localforage
};

Example using compose

import { createStore, combineReducers, compose } from 'redux';
import replicate from 'redux-replicate';
import localforage from 'redux-replicate-localforage';
import reducers from './reducers';
 
const initialState = {
  wow: 'such storage',
  very: 'cool'
};
 
const key = 'superCoolStorageUnit';
const reducerKeys = true;
const replicator = localforage;
const replication = replicate({ key, reducerKeys, replicator });
const create = compose(replication)(createStore);
const store = create(combineReducers(reducers), initialState);

Debouncing

By default, a debounce occurs when writing the next state to localforage (during onStateChange). The default timeout is 10 milliseconds. You can change it by doing this:

import localforage from 'redux-replicate-localforage';
 
localforage.debounce = 20;

Package Sidebar

Install

npm i redux-replicate-localforage

Weekly Downloads

1

Version

3.0.2

License

MIT

Last publish

Collaborators

  • timbur