Skip to content

Conversation

@BlooJeans
Copy link
Contributor

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

…o modifiers Previously: db.ref('/messages').on('child_added') db.ref('/messages').limitToFirst(1).on('child_added') db.ref('/messages').limitToLast(1).on('child_added') would add native listeners for the appropiarate queries, but when ANY of the three fired a child_added, than ALL three would receive it e.g. the limitToFirst child_added would get called when the *last* element changed We now keep track of the listeners by path as well as modifierString, and to a lesser extent, by eventType
@auser
Copy link
Contributor

auser commented Nov 14, 2016

Is this ready to go?

@BlooJeans
Copy link
Contributor Author

Not quite- I'll make a new PR soon which will include the immutable refs/queries as well as these commits.

@BlooJeans BlooJeans closed this Nov 14, 2016
@BlooJeans
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants