2.0.1 • Published 8 years ago

persist-reducer v2.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

Overview

Very simple function to allow persistence of a reducer's state to local storage. Note that this makes the reducer "impure" since it will have the side effect of persisting its state.

This works only in the browser.

Usage

import {saveState, restoreState} from 'persist-reducer'

const saveConfig = {
    storageKey: 'something unique',
    keysToSave: ['key1', key2']  // optional list of keys to include in saved state
}

const defaultState = restoreState(saveConfig, ...)

const reducer = saveState(saveConfig, function(state, action) {
    // normal reducer stuff
})

It is also possible to save / restore a specific value within an object by passing a property path in "keysToSave":

const saveConfig = {
  storageKey: 'unique value',
  keysToSave: ['myObject.myProperty']
}

With that configuration, myObject.myProperty will be saved but the other properties will not be touched.

Comparison with redux-persist

redux-persist is much more featureful. It also registers at the store level, as opposed to persist-reducer which is applied on a single reducer. This makes persist-reducer less intrusive in the project.

2.0.1

8 years ago

2.0.0

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago