fix(fast-element): every third subscriber not registered #3086
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug that occurred any time the 3rd subscriber was added to an observer.
Motivation & context
The
SubscriberSet
has internal optimizations that track the first two subscribers in fields, so it can avoid creating and pushing into an array for the most common scenarios. However, when the 3rd subscriber is added, it switches to an array, transferring the first two subscribers as part of that process. Then all future subscriptions just push into the array. The issue is that during that switch from fields to arrays, the 3rd subscription that triggered the process was not added to the array.This PR fixes the above issue but also:
SubscriberSet
andPropertyChangeNotifier
. Some looping was used to generate more tests than were manually written, in order to test different numbers of subscribers, since the above bug would not be caught by a simple set of breadth-based tests.SubscriberCollection
toSubscriberSet
which more accurately represents its behavior. This also involved adding ahas
method to the set, so that the presence of a subscriber could be checked. Finally bothSubscriberSet
andPropertyChangeNotifier
now keep track of the source object they are providing notifications for, so that it doesn't need to be passed in from the outside on notification (which seemed odd and non-ergonomic).Note: I turned linting off on the new test file. This is because I couldn't get the rules to match the scenarios and trying to match the code to the rules just created a test mess, with much less readable and more painful code. We should revisit this in the near future.
Issue type checklist
Is this a breaking change?
This is technically a breaking change to the notifier APIs, but it is unlikely to affect anyone.
Process & policy checklist