Permalink
Browse files

Breaking - make RCTDeviceEventEmitter warnings fatal

Reviewed By: davidaurelio

Differential Revision: D5469832

fbshipit-source-id: 1eb4ad3a2b3e1fa10d75e42d1d2f7baa291cb6f4
  • Loading branch information...
javache authored and facebook-github-bot committed Jul 24, 2017
1 parent 3eae3df commit db3df3400a80353a0140442a5045eca344dfc76f
Showing with 22 additions and 23 deletions.
  1. +22 −23 Libraries/EventEmitter/RCTDeviceEventEmitter.js
@@ -16,6 +16,20 @@ const EventSubscriptionVendor = require('EventSubscriptionVendor');
import type EmitterSubscription from 'EmitterSubscription';
function checkNativeEventModule(eventType: ?string) {
if (eventType) {
if (eventType.lastIndexOf('statusBar', 0) === 0) {
throw new Error('`' + eventType + '` event should be registered via the StatusBarIOS module');
}
if (eventType.lastIndexOf('keyboard', 0) === 0) {
throw new Error('`' + eventType + '` event should be registered via the Keyboard module');
}
if (eventType === 'appStateDidChange' || eventType === 'memoryWarning') {
throw new Error('`' + eventType + '` event should be registered via the AppState module');
}
}
}
/**
* Deprecated - subclass NativeEventEmitter to create granular event modules instead of
* adding all event listeners directly to RCTDeviceEventEmitter.
@@ -30,34 +44,19 @@ class RCTDeviceEventEmitter extends EventEmitter {
this.sharedSubscriber = sharedSubscriber;
}
_nativeEventModule(eventType: ?string) {
if (eventType) {
if (eventType.lastIndexOf('statusBar', 0) === 0) {
console.warn('`%s` event should be registered via the StatusBarIOS module', eventType);
return require('StatusBarIOS');
}
if (eventType.lastIndexOf('keyboard', 0) === 0) {
console.warn('`%s` event should be registered via the Keyboard module', eventType);
return require('Keyboard');
}
if (eventType === 'appStateDidChange' || eventType === 'memoryWarning') {
console.warn('`%s` event should be registered via the AppState module', eventType);
return require('AppState');
}
}
return null;
}
addListener(eventType: string, listener: Function, context: ?Object): EmitterSubscription {
const eventModule = this._nativeEventModule(eventType);
return eventModule ? eventModule.addListener(eventType, listener, context)
: super.addListener(eventType, listener, context);
if (__DEV__) {
checkNativeEventModule(eventType);
}
return super.addListener(eventType, listener, context);
}
removeAllListeners(eventType: ?string) {
const eventModule = this._nativeEventModule(eventType);
(eventModule && eventType) ? eventModule.removeAllListeners(eventType)
: super.removeAllListeners(eventType);
if (__DEV__) {
checkNativeEventModule(eventType);
}
super.removeAllListeners(eventType);
}
removeSubscription(subscription: EmitterSubscription) {

0 comments on commit db3df34

Please sign in to comment.