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

Feature: Implement SSE #52

Closed
benpate opened this issue Mar 7, 2021 · 4 comments
Closed

Feature: Implement SSE #52

benpate opened this issue Mar 7, 2021 · 4 comments

Comments

@benpate
Copy link
Contributor

benpate commented Mar 7, 2021

From discord:

server sse://whatever
    on foo
          -- additional commands.  "it" is populated with the event?
    end

    on message
        -- more commands
    end

on unhandled
@benpate
Copy link
Contributor Author

benpate commented Mar 9, 2021

@1cg -- This SSE code works but it's not ready to submit, yet.

I found an error reconnecting after I restart my SSE server (which is supposed to happen automatically). I'm working through a manual reconnect now, and will include that as an update to htmx, too, if necessary.

@benpate
Copy link
Contributor Author

benpate commented Mar 9, 2021

I've made some updates to this that are (nearly) ready for testing. I want to add public connect() and close() methods to the variable that's published into the hyperscript scope, and then I think this will be ready to go.

@1cg -- There's one experimental change that I wanted to get your eyes on before I move forward:

I'm using JSDoc-formatted comments in most of the new EventSource code. JSDoc works with the Typescript validator to provide fantastic insights and code validation if your set up your dev environment to use it. Otherwise, they're just specially formatted comments, so they are non-intrusive and don't require a build step or a compiler. You can run the raw code without any modifications.

What do you think? If this works for you, I'll take a pass at adding JSDoc comments in a separate PR. Like unit tests, the benefits grow exponentially as more code is covered :)

@benpate
Copy link
Contributor Author

benpate commented Mar 9, 2021

Another issue I'm having trouble with is parsing event names correctly. A regular, mixed case string seems to work fine. But if I include a number, or a dash - or a colon : then the parsing breaks. I think I'm probably using the wrong function to identify the event name. What is a better choice instead of parser.requireElement("dotOrColonPath"...)?

This was referenced Mar 9, 2021
@1cg
Copy link
Contributor

1cg commented Mar 11, 2021

parser.requireElement("stringLike") is more flexible, it will allow you to take either a string or a naked string, which is white space terminated.

@benpate benpate closed this as completed Mar 11, 2021
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

No branches or pull requests

2 participants