fanout/reconnecting-eventsource

Add some warning in README.md when overwriting method onmessage

Opened this issue · 0 comments

Hi,
first of all, thank you for this great library!

I recently had to dig into the library's code to understand why the property _lastEventIdwas not updated and why lastEventId was not appended to the url as I expected.
I think it would be nice to add some warning in the README.md file for following case :

  • Following code will update eventSource._lastEventId as expected:
const eventSource = new ReconnectingEventSource(...);

eventSource.addEventListener('message', event => {
    ...
});
  • But when method eventSource.onmessage is directly overwritten, the user has to manually update eventSource._lastEventId to reflect what previous code would do automatically:
const eventSource = new ReconnectingEventSource(...);

eventSource.onmessage = event => {
    eventSource._lastEventId = event.lastEventId;
    ...
};

Thank you!
Thierry.