mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
41b6884a1b
Summary: Changes the to-be-legacy `_EventSubscription` and `_EmitterSubscription` classes to implement the event-agnostic `EventSubscription` interface. This interface is valuable because it abstracts away the event definitions. Changelog: [Internal] Reviewed By: lunaleaps Differential Revision: D26155911 fbshipit-source-id: f94280976d4f9219f4780ac8fae0d5fbc1865386
45 lines
1.2 KiB
JavaScript
45 lines
1.2 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 strict
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import {type EventSubscription} from './EventSubscription';
|
|
import type EventSubscriptionVendor from './_EventSubscriptionVendor';
|
|
|
|
/**
|
|
* EventSubscription represents a subscription to a particular event. It can
|
|
* remove its own subscription.
|
|
*/
|
|
class _EventSubscription<EventDefinitions: {...}, K: $Keys<EventDefinitions>>
|
|
implements EventSubscription {
|
|
eventType: K;
|
|
key: number;
|
|
subscriber: EventSubscriptionVendor<EventDefinitions>;
|
|
listener: ?(...$ElementType<EventDefinitions, K>) => mixed;
|
|
context: ?$FlowFixMe;
|
|
|
|
/**
|
|
* @param {EventSubscriptionVendor} subscriber the subscriber that controls
|
|
* this subscription.
|
|
*/
|
|
constructor(subscriber: EventSubscriptionVendor<EventDefinitions>) {
|
|
this.subscriber = subscriber;
|
|
}
|
|
|
|
/**
|
|
* Removes this subscription from the subscriber that controls it.
|
|
*/
|
|
remove(): void {
|
|
this.subscriber.removeSubscription(this);
|
|
}
|
|
}
|
|
|
|
module.exports = _EventSubscription;
|