@samitouri / QOS-React / commits / 1c9dcd53d5

Add dynamic injection to ReactErrorUtils (#9246)

Dan Abramov committed Mar 23, 2017 at 18:45 UTC 1c9dcd53d5a5e194afc0d953a3341ad32fe311dc
1 file changed +17
src/renderers/shared/utils/ReactErrorUtils.js
+17
@@ -12,6 +12,8 @@
12
13 'use strict';
14
15 +const invariant = require('invariant');
16 +
17 let caughtError = null;
18
19 /**
@@ -24,6 +26,21 @@ let caughtError = null;
26 * @param {...*} args Arguments for function
27 */
28 const ReactErrorUtils = {
29 + injection: {
30 + injectErrorUtils(injectedErrorUtils: Object) {
31 + invariant(
32 + typeof injectedErrorUtils.invokeGuardedCallback === 'function',
33 + 'Injected invokeGuardedCallback() must be a function.',
34 + );
35 + invariant(
36 + typeof injectedErrorUtils.rethrowCaughtError === 'function',
37 + 'Injected rethrowCaughtError() must be a function.',
38 + );
39 + ReactErrorUtils.invokeGuardedCallback = injectedErrorUtils.invokeGuardedCallback;
40 + ReactErrorUtils.rethrowCaughtError = injectedErrorUtils.rethrowCaughtError;
41 + },
42 + },
43 +
44 invokeGuardedCallback: function<A, B, C, D, E, F, Context>(
45 name: string | null,
46 func: (a: A, b: B, c: C, d: D, e: E, f: F) => void,