Files
react-native/Libraries/EventEmitter/RCTDeviceEventEmitter.js
T
Tim YungandFacebook GitHub Bot c8c975f0d7 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
2021-02-03 22:04:40 -08:00

45 lines
1.4 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
import EventEmitter from '../vendor/emitter/EventEmitter';
import type EmitterSubscription from '../vendor/emitter/_EmitterSubscription';
import EventSubscriptionVendor from '../vendor/emitter/_EventSubscriptionVendor';
/**
* Deprecated - subclass NativeEventEmitter to create granular event modules instead of
* adding all event listeners directly to RCTDeviceEventEmitter.
*/
class RCTDeviceEventEmitter<
EventDefinitions: {...},
> extends EventEmitter<EventDefinitions> {
sharedSubscriber: EventSubscriptionVendor<EventDefinitions>;
constructor() {
const sharedSubscriber = new EventSubscriptionVendor<EventDefinitions>();
super(sharedSubscriber);
this.sharedSubscriber = sharedSubscriber;
}
removeSubscription<K: $Keys<EventDefinitions>>(
subscription: EmitterSubscription<EventDefinitions, K>,
): void {
if (subscription.emitter !== this) {
subscription.emitter.removeSubscription(subscription);
} else {
super.removeSubscription(subscription);
}
}
}
// FIXME: use typed events
type RCTDeviceEventDefinitions = $FlowFixMe;
export default (new RCTDeviceEventEmitter(): RCTDeviceEventEmitter<RCTDeviceEventDefinitions>);