Refactor debug logging
Summary: I dislike the sprinkled eslint ignores. Let's put this in one place and just depend on isProduction(). Reviewed By: jknoxville Differential Revision: D14913057 fbshipit-source-id: 2f5a98b7dba1ac1829eaeab24290d2f66820edf9
This commit is contained in:
committed by
Facebook Github Bot
parent
460260d620
commit
b276088f5f
@@ -36,6 +36,7 @@ export {
|
||||
LogLevel,
|
||||
} from './devices/BaseDevice.js';
|
||||
export {shouldParseAndroidLog} from './utils/crashReporterUtility.js';
|
||||
export {default as isProduction} from './utils/isProduction.js';
|
||||
export {createTablePlugin} from './createTablePlugin.js';
|
||||
export {default as DetailSidebar} from './chrome/DetailSidebar.js';
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
DetailSidebar,
|
||||
colors,
|
||||
styled,
|
||||
isProduction,
|
||||
} from 'flipper';
|
||||
import ImagesSidebar from './ImagesSidebar.js';
|
||||
import ImagePool from './ImagePool.js';
|
||||
@@ -55,9 +56,15 @@ const EmptySidebar = styled(FlexRow)({
|
||||
fontSize: 16,
|
||||
});
|
||||
|
||||
const DEBUG = false;
|
||||
const surfaceDefaultText = 'SELECT ALL SURFACES';
|
||||
|
||||
const debugLog = (...args) => {
|
||||
if (!isProduction()) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(...args);
|
||||
}
|
||||
};
|
||||
|
||||
export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
||||
static defaultPersistedState: PersistedState = {
|
||||
images: [],
|
||||
@@ -80,10 +87,7 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
||||
};
|
||||
|
||||
init() {
|
||||
if (DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('init()');
|
||||
}
|
||||
debugLog('init()');
|
||||
this.updateCaches('init');
|
||||
this.client.subscribe('events', (event: ImageEvent) => {
|
||||
const {surfaceList} = this.props.persistedState;
|
||||
@@ -170,10 +174,7 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
||||
});
|
||||
};
|
||||
updateCaches = (reason: string) => {
|
||||
if (DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Requesting images list (reason=' + reason + ')');
|
||||
}
|
||||
debugLog('Requesting images list (reason=' + reason + ')');
|
||||
this.client.call('listImages').then((response: ImagesListResponse) => {
|
||||
response.levels.forEach(data =>
|
||||
this.imagePool.fetchImages(data.imageIds),
|
||||
@@ -217,15 +218,9 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
||||
};
|
||||
|
||||
getImage = (imageId: string) => {
|
||||
if (DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('<- getImage requested for ' + imageId);
|
||||
}
|
||||
debugLog('<- getImage requested for ' + imageId);
|
||||
this.client.call('getImage', {imageId}).then((image: ImageData) => {
|
||||
if (DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('-> getImage ' + imageId + ' returned');
|
||||
}
|
||||
debugLog('-> getImage ' + imageId + ' returned');
|
||||
this.imagePool._fetchCompleted(image);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user