npm.io
2020.7.4-1 • Published 6 years ago

@grooveland/redux-storage

Licence
AGPL-3.0
Version
2020.7.4-1
Deps
0
Size
40 kB
Vulns
0
Weekly
0

@grooveland/redux-storage

Middleware to record status changes (Redux) and store them in the browser storage

DEPENDENCIES

@grooveland/redux-storage depends on redux.

Usage

yarn add @grooveland/redux-storage

or

npm i --save @grooveland/redux-storage

Inside the file where your redux store is configured you must import the initializer

import { storage } from '@grooveland/redux-storage';

Once imported you must configure the middleware and the pre-load function

const [preload, storageMiddleware] = storage({ type: 'session', key: 'grooveland' });

Finally we only have to load the initial state of the application from the selected storage.

const initState = {
    ...preload(),
};

and then we register the middleware inside the store

const composedEnhancers = compose(storageMiddleware);
export const store = createStore(reducer, composedEnhancers);

The middleware registers all changes within our state and stores them in the selected storage.

API

Description of the properties available within the storage method

Key Type Default Description
type StorageSettings local Type of storage used for data persistence
key string new Date().getTime() storage access key
StorageSettings

It only supports storage types such as local and session.

Keywords