Type ReactErrorUtils (#7565)
Christopher Chedeau committed
Aug 25, 2016 at 15:23 UTC
03e8c0eb754f142997094374baa7785e510392e3
1 file changed
+15
-3
src/renderers/shared/utils/ReactErrorUtils.js
+15
-3
@@ -7,6 +7,7 @@
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule ReactErrorUtils
10
+ * @flow
11
*/
12
13
'use strict';
@@ -16,12 +17,17 @@ var caughtError = null;
17
/**
18
* Call a function while guarding against errors that happens within it.
19
*
19
- * @param {?String} name of the guard to use for logging or debugging
20
+ * @param {String} name of the guard to use for logging or debugging
21
* @param {Function} func The function to invoke
22
* @param {*} a First argument
23
* @param {*} b Second argument
24
*/
24
-function invokeGuardedCallback(name, func, a, b) {
25
+function invokeGuardedCallback<A, B, C>(
26
+ name: string,
27
+ func: (a: A, b: B) => C,
28
+ a: A,
29
+ b: B,
30
+): ?C {
31
try {
32
return func(a, b);
33
} catch (x) {
@@ -64,11 +70,17 @@ if (__DEV__) {
70
typeof document !== 'undefined' &&
71
typeof document.createEvent === 'function') {
72
var fakeNode = document.createElement('react');
67
- ReactErrorUtils.invokeGuardedCallback = function(name, func, a, b) {
73
+ ReactErrorUtils.invokeGuardedCallback = function<A, B, C>(
74
+ name: string,
75
+ func: (a: A, b: B) => C,
76
+ a: A,
77
+ b: B,
78
+ ): ?C {
79
var boundFunc = func.bind(null, a, b);
80
var evtType = `react-${name}`;
81
fakeNode.addEventListener(evtType, boundFunc, false);
82
var evt = document.createEvent('Event');
83
+ // $FlowFixMe https://github.com/facebook/flow/issues/2336
84
evt.initEvent(evtType, false, false);
85
fakeNode.dispatchEvent(evt);
86
fakeNode.removeEventListener(evtType, boundFunc, false);