Permalink
Browse files

Add method on YellowBox to ignore warnings

Reviewed By: yungsters

Differential Revision: D4979460

fbshipit-source-id: 090a29009a1256809bd975184ad4957b2f6fc36d
  • Loading branch information...
Blair Vanderhoof authored and facebook-github-bot committed May 2, 2017
1 parent bf0a95d commit a974c140db605ecbdf8d3faa7a079b7e2dcebb09
Showing with 24 additions and 1 deletion.
  1. +24 −1 Libraries/ReactNative/YellowBox.js
@@ -33,6 +33,7 @@ type WarningInfo = {
const _warningEmitter = new EventEmitter();
const _warningMap: Map<string, WarningInfo> = new Map();
const IGNORED_WARNINGS: Array<string> = [];
/**
* YellowBox renders warnings at the bottom of the app being developed.
@@ -47,7 +48,11 @@ const _warningMap: Map<string, WarningInfo> = new Map();
* console.disableYellowBox = true;
* console.warn('YellowBox is disabled.');
*
* Warnings can be ignored programmatically by setting the array:
* Ignore specific warnings by calling:
*
* YellowBox.ignoreWarnings(['Warning: ...']);
*
* (DEPRECATED) Warnings can be ignored programmatically by setting the array:
*
* console.ignoredYellowBox = ['Warning: ...'];
*
@@ -153,6 +158,16 @@ function ensureSymbolicatedWarning(warning: string): void {
}
function isWarningIgnored(warning: string): boolean {
const isIgnored =
IGNORED_WARNINGS.some(
(ignoredWarning: string) => warning.startsWith(ignoredWarning)
);
if (isIgnored) {
return true;
}
// DEPRECATED
return (
Array.isArray(console.ignoredYellowBox) &&
console.ignoredYellowBox.some(
@@ -316,6 +331,14 @@ class YellowBox extends React.Component {
};
}
static ignoreWarnings(warnings: Array<string>): void {
warnings.forEach((warning: string) => {
if (IGNORED_WARNINGS.indexOf(warning) === -1) {
IGNORED_WARNINGS.push(warning);
}
});
}
componentDidMount() {
let scheduled = null;
this._listener = _warningEmitter.addListener('warning', warningMap => {

0 comments on commit a974c14

Please sign in to comment.