Skip to content

Commit cb6cbd1

Browse files
yungstersfacebook-github-bot
authored andcommitted
EventEmitter: Deprecate removeSubscription
Summary: Deprecates `EventEmitter#removeSubscription`. This required temporarily introducing a new `__removeSubscription` method that is only invoked by `EmitterSubscription`. This is necessary so that we do not completely break usages of `EventEmitter` that are supplying constructor arguments (which is also deprecated, but still supported until the next release). Calling this method will now cause a warning to appear with instructions to instead invoke `remove()` on the subscription itself. Lastly, changed `console.error` deprecation notice to instead use `console.warn`. This is in line with the principle that errors are "broken today" and warnings will be "broken tomorrow". Changelog: [General][Deprecated] - `EventEmitter#removeSubscription` is now deprecated. Reviewed By: rubennorte Differential Revision: D27704279 fbshipit-source-id: 581f5b2ab46b1bcfc1d20898b3d3392988dccbd5
1 parent 62934e5 commit cb6cbd1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Libraries/vendor/emitter/_EmitterSubscription.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class EmitterSubscription<EventDefinitions: {...}, K: $Keys<EventDefinitions>>
5454
* for removing the subscription lies with the EventEmitter.
5555
*/
5656
remove(): void {
57-
this.emitter.removeSubscription(this);
57+
this.emitter.__removeSubscription(this);
5858
}
5959
}
6060

Libraries/vendor/emitter/_EventEmitter.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ class EventEmitter<EventDefinitions: {...}> {
8282
*/
8383
removeSubscription<K: $Keys<EventDefinitions>>(
8484
subscription: EmitterSubscription<EventDefinitions, K>,
85+
): void {
86+
console.warn(
87+
'EventEmitter.removeSubscription(...): Method has been deprecated. ' +
88+
'Please instead use `remove()` on the subscription itself.',
89+
);
90+
this.__removeSubscription(subscription);
91+
}
92+
93+
/**
94+
* Called by `EmitterSubscription` to bypass the above deprecation warning.
95+
*/
96+
__removeSubscription<K: $Keys<EventDefinitions>>(
97+
subscription: EmitterSubscription<EventDefinitions, K>,
8598
): void {
8699
invariant(
87100
subscription.emitter === this,
@@ -147,7 +160,7 @@ class EventEmitter<EventDefinitions: {...}> {
147160
// FIXME: listeners should return void instead of mixed to prevent issues
148161
listener: (...$ElementType<EventDefinitions, K>) => mixed,
149162
): void {
150-
console.error(
163+
console.warn(
151164
`EventEmitter.removeListener('${eventType}', ...): Method has been ` +
152165
'deprecated. Please instead use `remove()` on the subscription ' +
153166
'returned by `EventEmitter.addListener`.',

0 commit comments

Comments
 (0)