Fix listeners with modifiers #123
Closed
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.
Fix listeners with modifiers reusing handles with the same path but no modifiers
We now keep track of the listeners by path as well as modifierString, and to a lesser extent, by eventType
Previously, if we have:
a)
db.ref('/messages').on('child_added')
b)
db.ref('/messages').limitToFirst(1).on('child_added')
c)
db.ref('/messages').limitToLast(1).on('child_added')
In short:
If we were to push a new message onto /messages, the 'b' query above with limitToFirst would fire its child_added listenerwould get called, despite only the last element having changed
Longer explanation:
it will reuse the same javascript subscription, and it will create 3 unique path+modifier references in the native code, to which we'll attach:
ios: only the appropriate listener
android: the multi-listener for all eventTypes
these listeners will fire correctly whenever (compare with a, b & c above):
a) anything gets added
b) when the last item changes
c) when the first item changes
but when any of these three listeners emit an event, all 3 will receive it