Skip to content
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

feat: enhanced turbo-train-stream-source JS API #11

Merged
merged 9 commits into from
Nov 25, 2024

Conversation

timaramazanov
Copy link
Collaborator

@timaramazanov timaramazanov commented Nov 24, 2024

Description

Added next public JS API:

  • init method - allows to init EventSource
  • destroy method - allows to destroy EventSource
  • state getter - returns humanized version of EventSource.readyState
  • no-turbo-stream param - to not call Turbo.connectStreamSource when it's not needed

Added proxy for EventSource events:

  • open
  • message
  • error
    So client JS doesn't need to access private #eventSource field.

Didn't implement reconnection logic inside component - as reconnection strategy might vary from case to case.

An example of reconnection strategy on client side:

onStreamError(event) {
      const error = event.detail
     console.log('An error occurred while attempting to connect to the Live Chat.', error)

      if (event.target.state !== 'open') {
        event.target.destroy()
        this.reconnectStreamTimer = setTimeout(() => {
          event.target.init()
          console.log('Attempting to reconnect to the SSE stream.')
        }, 5000) 
      }

Side fix

Remove node_modules from version control

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@timaramazanov timaramazanov self-assigned this Nov 24, 2024
aablinov and others added 7 commits November 25, 2024 14:54
@aablinov aablinov merged commit 7f25a27 into main Nov 25, 2024
4 checks passed
@aablinov aablinov deleted the enhance-web-component-api branch November 25, 2024 13:01
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.

None yet

2 participants