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,
|
LogLevel,
|
||||||
} from './devices/BaseDevice.js';
|
} from './devices/BaseDevice.js';
|
||||||
export {shouldParseAndroidLog} from './utils/crashReporterUtility.js';
|
export {shouldParseAndroidLog} from './utils/crashReporterUtility.js';
|
||||||
|
export {default as isProduction} from './utils/isProduction.js';
|
||||||
export {createTablePlugin} from './createTablePlugin.js';
|
export {createTablePlugin} from './createTablePlugin.js';
|
||||||
export {default as DetailSidebar} from './chrome/DetailSidebar.js';
|
export {default as DetailSidebar} from './chrome/DetailSidebar.js';
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import {
|
|||||||
DetailSidebar,
|
DetailSidebar,
|
||||||
colors,
|
colors,
|
||||||
styled,
|
styled,
|
||||||
|
isProduction,
|
||||||
} from 'flipper';
|
} from 'flipper';
|
||||||
import ImagesSidebar from './ImagesSidebar.js';
|
import ImagesSidebar from './ImagesSidebar.js';
|
||||||
import ImagePool from './ImagePool.js';
|
import ImagePool from './ImagePool.js';
|
||||||
@@ -55,9 +56,15 @@ const EmptySidebar = styled(FlexRow)({
|
|||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
});
|
});
|
||||||
|
|
||||||
const DEBUG = false;
|
|
||||||
const surfaceDefaultText = 'SELECT ALL SURFACES';
|
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> {
|
export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
||||||
static defaultPersistedState: PersistedState = {
|
static defaultPersistedState: PersistedState = {
|
||||||
images: [],
|
images: [],
|
||||||
@@ -80,10 +87,7 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (DEBUG) {
|
debugLog('init()');
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('init()');
|
|
||||||
}
|
|
||||||
this.updateCaches('init');
|
this.updateCaches('init');
|
||||||
this.client.subscribe('events', (event: ImageEvent) => {
|
this.client.subscribe('events', (event: ImageEvent) => {
|
||||||
const {surfaceList} = this.props.persistedState;
|
const {surfaceList} = this.props.persistedState;
|
||||||
@@ -170,10 +174,7 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
updateCaches = (reason: string) => {
|
updateCaches = (reason: string) => {
|
||||||
if (DEBUG) {
|
debugLog('Requesting images list (reason=' + reason + ')');
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Requesting images list (reason=' + reason + ')');
|
|
||||||
}
|
|
||||||
this.client.call('listImages').then((response: ImagesListResponse) => {
|
this.client.call('listImages').then((response: ImagesListResponse) => {
|
||||||
response.levels.forEach(data =>
|
response.levels.forEach(data =>
|
||||||
this.imagePool.fetchImages(data.imageIds),
|
this.imagePool.fetchImages(data.imageIds),
|
||||||
@@ -217,15 +218,9 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getImage = (imageId: string) => {
|
getImage = (imageId: string) => {
|
||||||
if (DEBUG) {
|
debugLog('<- getImage requested for ' + imageId);
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('<- getImage requested for ' + imageId);
|
|
||||||
}
|
|
||||||
this.client.call('getImage', {imageId}).then((image: ImageData) => {
|
this.client.call('getImage', {imageId}).then((image: ImageData) => {
|
||||||
if (DEBUG) {
|
debugLog('-> getImage ' + imageId + ' returned');
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('-> getImage ' + imageId + ' returned');
|
|
||||||
}
|
|
||||||
this.imagePool._fetchCompleted(image);
|
this.imagePool._fetchCompleted(image);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user