Skip to content

Commit

Permalink
RN: Remove RCTDeviceEventEmitter Checks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yungsters authored and facebook-github-bot committed Feb 4, 2021
1 parent 2bf866e commit c8c975f
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions Libraries/EventEmitter/RCTDeviceEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,6 @@ import EventEmitter from '../vendor/emitter/EventEmitter';
import type EmitterSubscription from '../vendor/emitter/_EmitterSubscription';
import EventSubscriptionVendor from '../vendor/emitter/_EventSubscriptionVendor';

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.
Expand All @@ -53,24 +27,6 @@ class RCTDeviceEventEmitter<
this.sharedSubscriber = sharedSubscriber;
}

addListener<K: $Keys<EventDefinitions>>(
eventType: K,
listener: (...$ElementType<EventDefinitions, K>) => mixed,
context: $FlowFixMe,
): EmitterSubscription<EventDefinitions, K> {
if (__DEV__) {
checkNativeEventModule(eventType);
}
return super.addListener(eventType, listener, context);
}

removeAllListeners<K: $Keys<EventDefinitions>>(eventType: ?K): void {
if (__DEV__) {
checkNativeEventModule(eventType);
}
super.removeAllListeners(eventType);
}

removeSubscription<K: $Keys<EventDefinitions>>(
subscription: EmitterSubscription<EventDefinitions, K>,
): void {
Expand Down

0 comments on commit c8c975f

Please sign in to comment.