1 |
3a515b92
|
cagy
|
// @flow
|
2 |
|
|
const isProduction: boolean = process.env.NODE_ENV === 'production';
|
3 |
|
|
|
4 |
|
|
export default function warning(condition: mixed, message: string): void {
|
5 |
|
|
// don't do anything in production
|
6 |
|
|
// wrapping in production check for better dead code elimination
|
7 |
|
|
if (!isProduction) {
|
8 |
|
|
// condition passed: do not log
|
9 |
|
|
if (condition) {
|
10 |
|
|
return;
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
// Condition not passed
|
14 |
|
|
const text: string = `Warning: ${message}`;
|
15 |
|
|
|
16 |
|
|
// check console for IE9 support which provides console
|
17 |
|
|
// only with open devtools
|
18 |
|
|
if (typeof console !== 'undefined') {
|
19 |
|
|
console.warn(text);
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
// Throwing an error and catching it immediately
|
23 |
|
|
// to improve debugging
|
24 |
|
|
// A consumer can use 'pause on caught exceptions'
|
25 |
|
|
// https://github.com/facebook/react/issues/4216
|
26 |
|
|
try {
|
27 |
|
|
throw Error(text);
|
28 |
|
|
} catch (x) {}
|
29 |
|
|
}
|
30 |
|
|
}
|