redux-storage-decorator-migrate

1.1.0 • Public • Published

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

Package Sidebar

Install

npm i redux-storage-decorator-migrate

Weekly Downloads

110

Version

1.1.0

License

MIT

Last publish

Collaborators

  • mathieudutour