redux-storage-decorator-migrate

Version storage with migration for redux-storage

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
redux-storage-decorator-migrate
2401.1.07 years ago8 years agoMinified + gzip package size for redux-storage-decorator-migrate in KB

Readme

redux-storage-decorator-migrate
build dependencies devDependencies
license npm version npm downloads
Migrate decorator for redux-storage to version the storage with migration

Installation

npm install --save redux-storage-decorator-migrate

Usage

Versioned storage with migrations.
import migrate from 'redux-storage-decorator-migrate'

engine = migrate(engine, 3);
engine.addMigration(1, (state) => { /* migration step for 1 */ return state; });
engine.addMigration(2, (state) => { /* migration step for 2 */ return state; });
engine.addMigration(3, (state) => { /* migration step for 3 */ return state; });

Testing migrations without a store (applying against ad-hoc state)

import {buildMigrationEngine} from 'redux-storage-decorator-migrate'
const versionKey = 'redux-storage-decorators-migrate-version'
 
const someTestState = {
  [versionKey]: 0,
  myFancyStateProperty: 'A'
}

const someExampleMigration = {
  version: 1,
  migration: (state) => ({...state, myFancyStateProperty: 'B'})
}

const migrationEngine = buildMigrationEngine(1, versionKey, [someExampleMigration])

const migratedState = migrationEngine(someTestState)

console.log(migratedState.myFancyStateProperty)
// B

License

MIT
redux-storage: https://github.com/michaelcontento/redux-storage redux-storage-decorator-migrate: https://github.com/mathieudutour/redux-storage-decorator-migrate