You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using an array of teardowns in our Subscriptions isn't ideal, performance-wise, for removing subscriptions.
Using a Set, rather than an Array would more closely mimic the behavior of most other common event registries, like EventTarget. Consider the following:
functionhandler(){console.log('handled');}consttarget=newEventTarget();target.addEventListener('unsubscribe',handler);target.addEventListener('unsubscribe',handler);target.addEventListener('unsubscribe',handler);target.dispatchEvent(newEvent('unsubscribe'));// Only fires `handler` once!target.removeEventListener('unsubscribe',handler);target.dispatchEvent(newEvent('unsubscribe'));// handler not fired (as it was removed)
This is in drastic contrast to our Subscription implementation, where the same subscription may be registered n times (which doesn't make sense, because it can only be torn down once), and the same function can also be registered n times, where it will execute n times.
Now, switching to using a Set internally would be a breaking change, as it would change how people can register and remove functions, more than anything. It's doubtful that it would be a breaking change for Subscriptions, because unsubscribe is idempotent.
Therefore we will not be able to do this until version 8.x.
The text was updated successfully, but these errors were encountered:
- Adding the same instance of a teardown more than once is the same as adding it once
- Removing a teardown with `Subscription.prototype.remove` will remove it much faster
BREAKING CHANGE: Adding the same function instance to a subscription as a teardown multiple times will now result in that function being executed only once on teardown. This brings us inline with the behavior of EventTarget, and also makes removing teardowns faster. The workaround is to make sure you are adding a new function instance to the Subscription each time if you need the same effect.
ResolvesReactiveX#6400
Related to this issue here: #5638
EventTarget
. Consider the following:This is in drastic contrast to our Subscription implementation, where the same subscription may be registered
n
times (which doesn't make sense, because it can only be torn down once), and the same function can also be registeredn
times, where it will executen
times.Now, switching to using a
Set
internally would be a breaking change, as it would change how people can register and remove functions, more than anything. It's doubtful that it would be a breaking change for Subscriptions, because unsubscribe is idempotent.Therefore we will not be able to do this until version 8.x.
The text was updated successfully, but these errors were encountered: