redux-storage-decorator-migrate
v1.1.0
Published
Version storage with migration for redux-storage
Downloads
721
Maintainers
Readme
redux-storage-decorator-migrate
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