0

我在我的 React 应用程序中使用 Reflux,并大量使用它的异步操作。

最近Uncaught (in promise) some-error,每当操作失败时,我都会在控制台中收到错误消息。

我研究了一下,发现 Reflux 每次触发 action 时都会创建一个 promise,如果 action 失败,promise 会拒绝并且没有人可以捕捉它。我把它归结为:

// create an action with completed/failed children
var action = Reflux.createAction({asyncResult:true});

// *** First scenario - throws error *** //
// invoke the action
action();
// somewhere the action has failed
action.failed("some reason"); // throws an error in the console - why??


// *** Second scenario - ok *** //
// invoke the action, but with a catch clause
action().catch(function(){});
// somewhere the action has failed
action.failed("some reason 2"); // this is now ok...

在这里提琴

似乎每个动作触发器都会创建一个承诺,并且在动作失败时会导致此问题。我想这只会在action.triggerPromise显式调用时发生,而不是每次都发生。

目前我必须catch在代码中的每个动作触发器上附加一个子句来解决这个问题。我希望我的组件只调用动作,而不是处理它们的结果。有没有办法避免它?我在这里错过了什么吗?

4

0 回答 0