在史诗中派遣动作的正确方法是什么?

What's the proper way to dispatch action inside epic?

在 redux-observable 史诗中调度 operationReset() 的正确方法是什么?

我应该导入实际商店并使用它吗?

It used to be like this, but following store is deprecated, and will be removed

// show operation failed message
(action$, store) => action$.ofType(OPERATION_FAILURE).map(() => (error({
    title: 'Operation Failed',
    message: 'Opps! It didn\'t go through.',
    action: {
        label: 'Try Again',
        autoDismiss: 0,
        callback: () => store.dispatch(operationReset())
    }
}))),

这可能会引发一个更大的问题,即应该如何使用回调进行通知,因为这意味着您要发送一个 non-JSON 可序列化函数作为操作的一部分。

我假设你仍然想匹配 React 通知系统。有一种方法可以使用 Observable.create:

(action$, store) =>
  action$.pipe(
    ofType(OPERATION_FAILURE),
    mergeMap(() =>
      Observable.create(observer => {
        observer.next(
          error({
            title: "Operation Failed",
            message: "Oops! It didn't go through.",
            action: {
              label: "Try Again",
              autoDismiss: 0,
              callback: () => {
                // Send off a reset action
                observer.next(operationReset());
                // Close off this observable
                observer.complete();
              },
              // If the notification is dismissed separately (can they click an x?)
              onRemove: () => observer.complete()
            }
          })
        );
      })
    )
  );

注意:我仍然不想将回调作为操作的一部分发送。有趣的是,我的一个项目也使用了该通知系统组件——我们有 epics 可以添加通知并根据操作清除通知。所有操作保持纯粹,通知系统是受控的副作用。