wallet-core/node_modules/fbjs/lib/warning.js

64 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-05-03 15:35:00 +02:00
/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyFunction = require('./emptyFunction');
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if (process.env.NODE_ENV !== 'production') {
2017-08-14 05:01:11 +02:00
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// 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) {}
};
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
2017-05-03 15:35:00 +02:00
}
2017-08-14 05:01:11 +02:00
printWarning.apply(undefined, [format].concat(args));
}
};
2017-05-03 15:35:00 +02:00
}
module.exports = warning;