diff --git a/Libraries/AppRegistry/AppRegistry.js b/Libraries/AppRegistry/AppRegistry.js index a5fa0e305..8e85c8940 100644 --- a/Libraries/AppRegistry/AppRegistry.js +++ b/Libraries/AppRegistry/AppRegistry.js @@ -89,9 +89,7 @@ var AppRegistry = { ', development-level warning are ' + (__DEV__ ? 'ON' : 'OFF') + ', performance optimizations are ' + (__DEV__ ? 'OFF' : 'ON'); infoLog(msg); - BugReporting.init(); BugReporting.addSource('AppRegistry.runApplication' + runCount++, () => msg); - BugReporting.addFileSource('react_hierarchy.txt', () => require('dumpReactTree')()); invariant( runnables[appKey] && runnables[appKey].run, 'Application ' + appKey + ' has not been registered. This ' + diff --git a/Libraries/BugReporting/BugReporting.js b/Libraries/BugReporting/BugReporting.js index e86eeacdc..9af291d6c 100644 --- a/Libraries/BugReporting/BugReporting.js +++ b/Libraries/BugReporting/BugReporting.js @@ -22,6 +22,10 @@ type ExtraData = { [key: string]: string }; type SourceCallback = () => string; type DebugData = { extras: ExtraData, files: ExtraData }; +function defaultExtras() { + BugReporting.addFileSource('react_hierarchy.txt', () => require('dumpReactTree')()); +} + /** * A simple class for collecting bug report data. Components can add sources that will be queried when a bug report * is created via `collectExtraData`. For example, a list component might add a source that provides the list of rows @@ -33,13 +37,11 @@ class BugReporting { static _fileSources: Map = new Map(); static _subscription: ?EmitterSubscription = null; - /** - * `init` is called in `AppRegistry.runApplication`, so you shouldn't have to worry about it. - */ - static init() { + static _maybeInit() { if (!BugReporting._subscription) { BugReporting._subscription = RCTDeviceEventEmitter .addListener('collectBugExtraData', BugReporting.collectExtraData, null); + defaultExtras(); } } @@ -68,6 +70,7 @@ class BugReporting { } static _addSource(key: string, callback: SourceCallback, source: Map): {remove: () => void} { + BugReporting._maybeInit(); if (source.has(key)) { console.warn(`BugReporting.add* called multiple times for same key '${key}'`); }