Skip to content

Commit

Permalink
Add method on YellowBox to ignore warnings
Browse files Browse the repository at this point in the history
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 a974c14
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Libraries/ReactNative/YellowBox.js
Expand Up @@ -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.
Expand All @@ -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: ...'];
*
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit a974c14

Please sign in to comment.