File size: 929 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* eslint-disable no-console, no-empty */
export const warnCache = {
current: {},
};
/**
* Logs a warning if the condition is not met.
* This is used to log issues in development environment only.
*/
export function warn(condition: boolean, message: string) {
if (!__DEV__) {
return;
}
if (condition) {
return;
}
const sanitizedMessage = message.trim();
const hasAlreadyPrinted = warnCache.current[sanitizedMessage];
if (!hasAlreadyPrinted) {
warnCache.current[sanitizedMessage] = true;
const warning = `[InstantSearch] ${sanitizedMessage}`;
console.warn(warning);
try {
// Welcome to debugging InstantSearch.
//
// This error was thrown as a convenience so that you can find the source
// of the warning that appears in the console by enabling "Pause on exceptions"
// in your debugger.
throw new Error(warning);
} catch (error) {}
}
}
|