index.js 851 B

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