Redux 状态缺少来自 redux offline 的 "offline" 部分

Redux state is missing "offline" part from redux offline

我在我的 Angular 项目中使用 Redux Offline,现在我想在离线模式下启用取消发件箱中的项目。基本上,我只想过滤发件箱数组以删除我想要 cancel/modify.

的项目

我的问题是它从我在顶级减速器中收到的状态中丢失(未定义)。我在Redux Dev工具里可以看到offline,也可以通过NgRedux.select()和NgRedux.getState().

获取

redux offline 没有出现在 reducer 接收到的状态中有什么原因吗?我可以添加它,然后通过 reducer 更改它吗?或者有没有其他访问和修改发件箱的方法?

package.json:

"dependencies": {
 "@angular-redux/router": "^7.0.0",
 "@angular-redux/store": "^9.0.0",
 "@angular/animations": "^6.0.3",
 "@angular/common": "^6.0.3",
 "@angular/compiler": "^6.0.3",
 "@angular/core": "^6.0.3",
 "@angular/forms": "^6.0.3",
 "@angular/http": "^6.0.3",
 "@angular/platform-browser": "^6.0.3",
 "@angular/platform-browser-dynamic": "^6.0.3",
 "@angular/pwa": "^0.6.7",
 "@angular/router": "^6.0.3",
 "@angular/service-worker": "^6.0.3",
 "@redux-offline/redux-offline": "^2.3.3",
 "core-js": "^2.5.7",
 "reduce-reducers": "^0.3.0",
 "redux": "^4.0.0",
 "redux-observable": "1.0.0-alpha.2",
 "rxjs": "^6.2.0",
 "rxjs-compat": "^6.2.0",
 "zone.js": "^0.8.26"
},
"devDependencies": {
 "redux-devtools-extension": "^2.13.2",
 "@angular-devkit/build-angular": "^0.6.7",
 "@angular/cli": "^6.0.7",
 "@angular/compiler-cli": "^6.0.3",
 "@angular/language-service": "^6.0.3",
 "@types/jasmine": "^2.8.8",
 "@types/jasminewd2": "~2.0.3",
 "@types/node": "^8.10.18",
 "codelyzer": "^4.3.0",
 "jasmine-core": "~2.99.1",
 "jasmine-spec-reporter": "~4.2.1",
 "karma": "~1.7.1",
 "karma-chrome-launcher": "~2.2.0",
 "karma-coverage-istanbul-reporter": "^1.4.3",
 "karma-jasmine": "^1.1.2",
 "karma-jasmine-html-reporter": "^0.2.2",
 "opn-cli": "^3.1.0",
 "protractor": "^5.3.2",
 "ts-node": "~5.0.1",
 "tslint": "~5.9.1",
 "typescript": "~2.7.2"
}

如果您需要更多信息,请发表评论。

redux-offline 动态注入它自己的减速器,因此您将无法通过顶级减速器访问它。 redux-offline 通过配置公开它的 queue,这将允许您将发件箱更新为 remove/add 操作。如果您想在用户离线时删除离线操作,我建议使用特定操作类型(例如 'CANCEL_OFFLINE_ACTION')进行离线操作调用,并在 queue.enqueue 中处理它以删除您不想传播的发件箱。

这是一个粗略的例子:

// the action to dispatch
const action = {
  type: 'CANCEL_OFFLINE_ACTION',
  payload: {
    id: 123,
  },
  meta: {
    offline: {
      effect: {
        url: ''
      },
    },
  },
};

// the custom enqueue action
function enqueue(outbox, incomingAction) {
  return incomingAction.type !== 'CANCEL_OFFLINE_ACTION' ? [...outbox, incomingAction] :
    outbox.filter(
      outboxAction => outboxAction.payload.id !== incomingAction.payload.id,
    );
}