Skip to content

Commit

Permalink
EventEmitter: Deprecate Constructor Argument
Browse files Browse the repository at this point in the history
Summary:
Deprecates the constructor argument to `EventEmitter`.

It was only ever used by React Native to instantiate a `NativeEventEmitter` with the same "vendor" as `RCTDeviceEventEmitter`, which was a gross violation of encapsulation that led to an overcomplicated implementation of `EventEmitter`. I am now untangling that mess.

Changelog:
[General][Deprecated] - It is now deprecated to pass a constructor argument to `EventEmitter(...)`.

Reviewed By: rubennorte

Differential Revision: D27704182

fbshipit-source-id: 102f26a8a9c029f0e7a1346dc2f2d9f2548d6a42
  • Loading branch information
yungsters authored and facebook-github-bot committed Apr 12, 2021
1 parent 9d263aa commit 14f7a2b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Libraries/vendor/emitter/_EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ export interface IEventEmitter<EventDefinitions: {...}> {
*/
class EventEmitter<EventDefinitions: {...}>
implements IEventEmitter<EventDefinitions> {
_subscriber: EventSubscriptionVendor<EventDefinitions>;
_subscriber: EventSubscriptionVendor<EventDefinitions> = new EventSubscriptionVendor<EventDefinitions>();

/**
* @constructor
*
* @param {EventSubscriptionVendor} subscriber - Optional subscriber instance
* to use. If omitted, a new subscriber will be created for the emitter.
*/
constructor(subscriber: ?EventSubscriptionVendor<EventDefinitions>) {
this._subscriber =
subscriber || new EventSubscriptionVendor<EventDefinitions>();
if (subscriber != null) {
console.warn('EventEmitter(...): Constructor argument is deprecated.');
this._subscriber = subscriber;
}
}

/**
Expand Down

0 comments on commit 14f7a2b

Please sign in to comment.