Skip to content

Commit c8c975f

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Remove RCTDeviceEventEmitter Checks
Summary: Removes the checks in `RCTDeviceEventEmitter` that were initially added to migrate call sites to other modules when `NativeEventEmitter` was introduced. This set of checks is problematic for a few reasons: 1. Does not cover many other events that have since been introduced, so the small list covered is arbitrary. 2. Prevents composition of `RCTDeviceEventEmitter` in the implementation of those modules. 3. Code bloat. Changelog: [General][Removed] - `RCTDeviceEventEmitter` no longer throws for `SttatusBar`, `Keyboard`, and `AppState` events. However, you are still recommended to use the more appropriate modules for listening to these events. Reviewed By: lunaleaps Differential Revision: D26163602 fbshipit-source-id: 316287bfdf2947fe85d022a3f83a205e89c432ba
1 parent 2bf866e commit c8c975f

File tree

1 file changed

+0
-44
lines changed

1 file changed

+0
-44
lines changed

Libraries/EventEmitter/RCTDeviceEventEmitter.js

-44
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,6 @@ import EventEmitter from '../vendor/emitter/EventEmitter';
1212
import type EmitterSubscription from '../vendor/emitter/_EmitterSubscription';
1313
import EventSubscriptionVendor from '../vendor/emitter/_EventSubscriptionVendor';
1414

15-
function checkNativeEventModule(eventType: ?string) {
16-
if (eventType) {
17-
if (eventType.lastIndexOf('statusBar', 0) === 0) {
18-
throw new Error(
19-
'`' +
20-
eventType +
21-
'` event should be registered via the StatusBarIOS module',
22-
);
23-
}
24-
if (eventType.lastIndexOf('keyboard', 0) === 0) {
25-
throw new Error(
26-
'`' +
27-
eventType +
28-
'` event should be registered via the Keyboard module',
29-
);
30-
}
31-
if (eventType === 'appStateDidChange' || eventType === 'memoryWarning') {
32-
throw new Error(
33-
'`' +
34-
eventType +
35-
'` event should be registered via the AppState module',
36-
);
37-
}
38-
}
39-
}
40-
4115
/**
4216
* Deprecated - subclass NativeEventEmitter to create granular event modules instead of
4317
* adding all event listeners directly to RCTDeviceEventEmitter.
@@ -53,24 +27,6 @@ class RCTDeviceEventEmitter<
5327
this.sharedSubscriber = sharedSubscriber;
5428
}
5529

56-
addListener<K: $Keys<EventDefinitions>>(
57-
eventType: K,
58-
listener: (...$ElementType<EventDefinitions, K>) => mixed,
59-
context: $FlowFixMe,
60-
): EmitterSubscription<EventDefinitions, K> {
61-
if (__DEV__) {
62-
checkNativeEventModule(eventType);
63-
}
64-
return super.addListener(eventType, listener, context);
65-
}
66-
67-
removeAllListeners<K: $Keys<EventDefinitions>>(eventType: ?K): void {
68-
if (__DEV__) {
69-
checkNativeEventModule(eventType);
70-
}
71-
super.removeAllListeners(eventType);
72-
}
73-
7430
removeSubscription<K: $Keys<EventDefinitions>>(
7531
subscription: EmitterSubscription<EventDefinitions, K>,
7632
): void {

0 commit comments

Comments
 (0)