我如何持续嵌套的redux商店

发布于 2025-01-18 10:29:44 字数 855 浏览 3 评论 0原文

我想坚持我的redux商店的嵌套对象。我尝试了 https://github.com/rt2zz/redux-persist 包装在我的情况下工作。我想知道是否可以定义这样的白名单:'user.statuses.verification.isdone'

这是我的商店:

{
    user: {
        statuses: {
            verification: { isPending: true, isDone: false },
            activation: { isPending: true, isDone: false },
            set1: { isPending: true, isDone: false, refNumber: xxx },
            set2: { isPending: true, isDone: false, refNumber: xxx },
        },
    },
}

我只想在每个状态和“ refnumber”中坚持“ isdone”。 谁能帮我吗?

我已经尝试过如Redux持续文档中所述的嵌套持续存在 httpps://github.com/rt2zz zzz /redux-persist#嵌套派者,但看起来它的限制为2级。

I want to persist nested object of my redux store. I tried https://github.com/rt2zz/redux-persist package but it doesn't work in my case. I wonder if it's possible to define a whitelist like this: 'user.statuses.verification.isDone'

This is my store:

{
    user: {
        statuses: {
            verification: { isPending: true, isDone: false },
            activation: { isPending: true, isDone: false },
            set1: { isPending: true, isDone: false, refNumber: xxx },
            set2: { isPending: true, isDone: false, refNumber: xxx },
        },
    },
}

I want to persist only "isDone" in every of statuses and "refNumber".
Can anyone help me?

I already tried nested persist as described in redux persist documentation https://github.com/rt2zz/redux-persist#nested-persists but looks like it has a limitation to 2 levels.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漫雪独思 2025-01-25 10:29:44

我尝试了这 https://stackoverflow.com/a/71616665 ,它运行得很好。 在此示例中,您可以看到黑名单,但您只需要用白名单替换它即可。

const config = getPersistConfig({
    key: 'root',
    storage: AsyncStorage,
    whitelist: [
        'user.statuses.verification.isDone’,  
        'user.statuses.activation.isDone’,  
        'user.statuses.set1.isDone’,
        'user.statuses.set1.refNumber’,
        'user.statuses.set2.isDone’,
        'user.statuses.set2.refNumber’,
    ],
    rootReducer, // your root reducer must be also passed here
    ... // any other props from the original redux-persist config omitting the stateReconciler
})

I tried this https://stackoverflow.com/a/71616665 and it works perfectly. 
In this example you can see the blacklist but you just need to replace it with the whitelist.

const config = getPersistConfig({
    key: 'root',
    storage: AsyncStorage,
    whitelist: [
        'user.statuses.verification.isDone’,  
        'user.statuses.activation.isDone’,  
        'user.statuses.set1.isDone’,
        'user.statuses.set1.refNumber’,
        'user.statuses.set2.isDone’,
        'user.statuses.set2.refNumber’,
    ],
    rootReducer, // your root reducer must be also passed here
    ... // any other props from the original redux-persist config omitting the stateReconciler
})
梦旅人picnic 2025-01-25 10:29:44

您需要使用这个包: https://github.com/edy/redux-persist -transform-filter

“问题”已经得到解决,它更多的是一个精确的实现选择,而不是维护者认为的问题,并且您有几种不同的方法来解决它:

redux-persist - 如何将嵌套状态列入黑名单/白名单

You need to use this package: https://github.com/edy/redux-persist-transform-filter

The "issue" has already been addressed, it's more a precise implementation choice, not an issue according to the maintainers, and you have several different ways to address it:

redux-persist - how do you blacklist/whitelist nested state

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文