From 1dbc90604d7afed4a94648e4bce3b81f6cf2add9 Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Sat, 22 Oct 2016 00:36:42 +0200 Subject: [PATCH] Add utils/warning.js --- src/utils/warning.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/utils/warning.js diff --git a/src/utils/warning.js b/src/utils/warning.js new file mode 100644 index 000000000..db0f7bcd1 --- /dev/null +++ b/src/utils/warning.js @@ -0,0 +1,29 @@ +const __DEV__ = ( + typeof process !== 'undefined' && + process.env && + process.env.NODE_ENV !== 'production' +) + +/** + * Log a development warning. + * @param {String} message + */ + +export default function warning(message) { + if (!__DEV__) { + return + } + + if (typeof console !== 'undefined') { + console.error('Warning: ', message) // eslint-disable-line no-console + } + + try { + // --- Welcome to debugging Slate --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message) + } catch (x) { + // This error is only for debugging + } +}