Skip to content

Additional Event Firing Fix#1

Closed
the-c0d3r wants to merge 1 commit intoAqsa-K:masterfrom
the-c0d3r:patch-1
Closed

Additional Event Firing Fix#1
the-c0d3r wants to merge 1 commit intoAqsa-K:masterfrom
the-c0d3r:patch-1

Conversation

@the-c0d3r
Copy link
Copy Markdown

@the-c0d3r the-c0d3r commented Jul 13, 2018

I tested the code and it seem like the event streaming is fired as soon as you start the stream on a reference which already have data in the database. Therefore I modified the code to check for the last_value and only fire the event if the value is changed. I modified this to fit my needs, maybe somebody will find this useful as well. Thanks for your commit adding the SSE client.


Original comment from this discussion

I tried your fork repo, somehow it fires off an event as soon as I set the stream() and the callback function is called immediately. But the intended listening event is triggered every time when the data is changed in the database side.

>>> ref.stream(callbackfunc)
<firebase_admin.db.Stream object at 0x10c9b7ef0>
>>> {'event': 'put', 'data': True, 'path': '/'}
>>> # The event above is fired off automatically on stream without modification on db

>>> # these 3 events below are fired off by the changes in the db. 
>>> {'event': 'put', 'data': 'true', 'path': '/'}
>>> {'event': 'put', 'data': 'false', 'path': '/'}
>>> {'event': 'put', 'data': 'true', 'path': '/'}

>>> self.db.reference("/users/dev1/successful").stream(callbackfunc)
<firebase_admin.db.Stream object at 0x10ef897f0>
>>> {'event': 'put', 'data': True, 'path': '/'}
>>> # The event above is fired off automatically on stream without modification on db

Is it possible to fix this unexpected behavior? I would like to help fix it, but I have no idea where to start looking and I have never worked with SSE before. If anyone can point me in correct direction, please do.

I tested the code and it seem like the event streaming is fired as soon as you start the stream on a reference which already have data in the database. Therefore I modified the code to check for the `last_value` and only fire the event if the value is changed. I modified this to fit my needs, maybe somebody will find this useful as well. Thanks for your commit adding the SSE client.
@the-c0d3r
Copy link
Copy Markdown
Author

Since this feature has been merged into Firebase, I will be closing this.

@the-c0d3r the-c0d3r closed this Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant