-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add done
event
#63
base: master
Are you sure you want to change the base?
Add done
event
#63
Conversation
README.md
Outdated
### Done vs Close | ||
|
||
`done` events will fire when server closes the connection. | ||
Reconnections will occur indefinitely, unless this behavior is disabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be rephrased slightly to make it more clear. Maybe something like:
By default, the client will automatically reconnect when this happens. You can disable the reconnections by setting the pollingInterval
option to 0".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. Updated.
src/EventSource.js
Outdated
@@ -115,6 +116,7 @@ class EventSource { | |||
this._handleEvent(xhr.responseText || ''); | |||
|
|||
if (xhr.readyState === XMLHttpRequest.DONE) { | |||
this.dispatch('done', { type: 'done' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly recommend to dispatch the done
event after calling _pollAgain
. This would allow users to cancel the reconnection by calling .close()
from the done
handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I just updated and tested that it works as expected.
This allows 'close' called from a 'done' handler to cancel the upcoming reconnection. Otherwise '_pollTimer' will get reset after the handler.
LGTM 👍 |
any idea when this will merge? :) |
See my original issue #56 for some background.
Currently the library only supports
close
events, which fire when the connection is closed from the client side. An additional event for tracking server side closing of the connection would be useful. This PR adds adone
event to do that. Luckily most of the plumbing is already there, so it was easy to hook up the new event. As far as naming goes, I just matched the state name like most other events seem to do. It still might be a little confusing, so I added some text to the README.