allegro/redux-storage-decorator-engines

Name: redux-storage-decorator-engines

Owner: Allegro Tech

Description: Composing decorator for redux-storage to use different storage types

Created: 2016-06-03 09:32:40.0

Updated: 2018-04-07 15:11:57.0

Pushed: 2018-04-07 15:11:56.0

Homepage:

Size: 10

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

redux-storage-decorator-engines

Build Status

Composing decorator for redux-storage to use different storage types like redux-storage-engine-localstorage or redux-storage-engine-sessionstorage including custom engines (i.e. to load information from cookies) in a single application.

Installation
npm install --save redux-storage-decorator-engines
Usage

Along with redux-storage-decorator-filter you can define different persistence policy for each part of a state. Simply create the stores as you normally would do and wrap them with the decorator.

rt engines from 'redux-storage-decorator-engines';
rt filter from 'redux-storage-decorator-filter';
rt createLocalStorageEngine from 'redux-storage-engine-localstorage';
rt createSessionStorageEngine from 'redux-storage-engine-sessionstorage';

t localStorageEngine = filter(createLocalStorageEngine('redux'), ['todos']);
t sessionStorageEngine = filter(createSessionStorageEngine('redux'), ['visibilityFilter']);

t storageEngine = engines([
calStorageEngine,
ssionStorageEngine

To include information from a cookie in a redux state for later easy access simply provide a custom storage engine:

rt Cookies from 'js-cookie';

t cookieStorage = {
ad() {
const state = {
  cookie: Cookies.get('cookie')
};
return Promise.resolve(state);

ve() {
return Promise.resolve();



t storageEngine = engines([
calStorageEngine,
ssionStorageEngine,
okieStorage

NOTE: If the same state key is loaded from more than one storage engine an application state upon load is not deterministic. A final state depends on the actual order of the loads. In such a case a warning message is emitted on non-production environments (an environment is considered a production if NODE_ENV is set to production).

License

redux-storage-decorator-engines is published under Apache License 2.0.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.