[英]Redux-persist migration not migrating
I want to write a migration for redux-persist, but somehow migration is not being applied.我想为 redux-persist 编写迁移,但不知何故没有应用迁移。 I've followed the official documentation about migrations: https://github.com/rt2zz/redux-persist/blob/master/docs/migrations.md我遵循了有关迁移的官方文档: https://github.com/rt2zz/redux-persist/blob/master/docs/migrations.md
But something in the code below is not working since my redux-persist is not applying the migration.但是下面代码中的某些内容不起作用,因为我的 redux-persist 没有应用迁移。
When I try to debug this migration it says that version number is the same.当我尝试调试此迁移时,它说版本号是相同的。
Redux-persist version match noop migration redux-persist 版本匹配 noop 迁移
Not sure if I'm missing something in the config or migration writing.不确定我是否在配置或迁移写作中遗漏了一些东西。
In my store I have something like this for persist configuration在我的商店中,我有类似的东西用于持久配置
const persistConfig: PersistConfig = {
key: 'primary',
storage,
blacklist: [
],
stateReconciler: autoMergeLevel2,
version: 1,
migrate: createMigrate(migrations, { debug: true })
} as PersistConfig;
and my migration looks like:我的迁移看起来像:
const migrations = {
0: (state: StoreState) => {
return {
...state,
application: {
...state.application
}
}
},
1: (state: StoreState) => {
return {
...state,
application: {
...state.application,
items:[{id: 1, isDone: false}, {id: 2, isDone: false}].map((item, index)=>{
if(item.id == 1){
item.isDone = true
}
}),
},
}
}
}
In my first version of the state and application reducer I had object items which looked like this:在我的第一个版本的 state 和应用程序减速器中,我有 object 项目,如下所示:
items:[
{id: 1},
{id: 2}
]
and now it needs to look like:现在它需要看起来像:
items:[
{id: 1, isDone: false/true},
{id: 2, isDone: false/true}
]
You need to upgrade the version in persistConfig
object for redux-persist
. redux-persist
需要升级persistConfig
object 中的版本。 If a migration has run for a version once it will not run again for the same version.如果迁移已经为一个版本运行一次,它将不会再次为同一版本运行。
const persistConfig = {
key: "root",
storage,
version: 0,
migrate: createMigrate(migrations, { debug: true }),
stateReconciler: autoMergeLevel2, // see "Merge Process" section for details.
whitelist: ["auth", "user", "app", "card"]
};
const persistConfig = {
key: "root",
storage,
version: 1,
migrate: createMigrate(migrations, { debug: true }),
stateReconciler: autoMergeLevel2, // see "Merge Process" section for details.
whitelist: ["auth", "user", "app", "card"]
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.