refactor BugReporting to use RCTDeviceEventEmitter

Reviewed By: sahrens

Differential Revision: D3212300

fb-gh-sync-id: 3a61d620320dd1c0254bf3b836601d5bbfbc4c0d
fbshipit-source-id: 3a61d620320dd1c0254bf3b836601d5bbfbc4c0d
This commit is contained in:
Felix Oghina 2016-04-22 11:23:21 -07:00 committed by Facebook Github Bot 8
parent cbdf026628
commit 7946160733
1 changed files with 8 additions and 5 deletions

View File

@ -11,8 +11,10 @@
*/ */
'use strict'; 'use strict';
const BatchedBridge = require('BatchedBridge');
const BugReportingNativeModule = require('NativeModules').BugReporting; const BugReportingNativeModule = require('NativeModules').BugReporting;
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
import type {EmitterSubscription} from 'EventEmitter';
type ExtraData = { [key: string]: string }; type ExtraData = { [key: string]: string };
type SourceCallback = () => string; type SourceCallback = () => string;
@ -26,15 +28,16 @@ type SourceCallback = () => string;
class BugReporting { class BugReporting {
static _sources: Map<string, SourceCallback> = new Map(); static _sources: Map<string, SourceCallback> = new Map();
static _subscription: EmitterSubscription = null;
/** /**
* `init` is called in `AppRegistry.runApplication`, so you shouldn't have to worry about it. * `init` is called in `AppRegistry.runApplication`, so you shouldn't have to worry about it.
*/ */
static init() { static init() {
BatchedBridge.registerCallableModule( // idempotent if (!BugReporting._subscription) {
'BugReporting', BugReporting._subscription = RCTDeviceEventEmitter
BugReporting, .addListener('collectBugExtraData', BugReporting.collectExtraData, null);
); }
} }
/** /**