redux-persist,使用“转换”仅保存前10个项目

时间:2018-11-02 13:04:06

标签: redux redux-persist

在通过redux-persist保留时,我仅尝试保存2个项目。

我很困惑下面的代码为什么不起作用。 (它似乎节省了2个以上项目)

const myTransform = createTransform(
  (inboundState, key) => {

    let { openforum_threads } = inboundState

    if (!openforum_threads) {
      return inboundState
    }

    let { allIds } = openforum_threads

    let STORE_NUM = 2
    let storeIds = allIds.slice(0, STORE_NUM)
    console.log('saving', storeIds)
    let { byId } = openforum_threads

    let storeById = {}
    storeIds.map((id) => {
      storeById[id] = byId[id]
    })

    openforum_threads = {
      ...openforum_threads,
      allIds: storeIds,
      byId: storeById
    }


    return { ...inboundState, openforum_threads}
  },
  (outboundState, key) => {
    // convert mySet to an Array.
    return outboundState
  }
)

0 个答案:

没有答案