dan-cooke / remix-sse

Server Sent Events (SSE) for the remix framework
Apache License 2.0
71 stars 3 forks source link

New `useEventStream` hook, remove `RemixSseProvider` and `useEventSource` #20

Closed dan-cooke closed 7 months ago

dan-cooke commented 7 months ago

No more boilerplate

I wasn't happy with the amount of boilerplate even after making several changes like making the eventKey default to 'message'

The library should not provide the context, if users want to share their event sources across their app they are free to do so, but remix-sse should not care about this.

So the following changes all have the intention of making the library easier to get started with.

How to migrate

useSubscribe now takes an EventSource

--- const data = useSubscribe('/emitter', 'event-key')
+++ const data = useSubscribe(new EventSource('/emitter'), { eventKey: 'event-key'})

This was purely to make room for the next change

useEventStream is the MVP now

Use this hook wherever possible, it will create the EventSource for you and call useSubscribe making sure to not duplicate Eventsources to the same URL using a simple map.


const data = useEventStream('/emitter')

Removed the context and useEventStream

No need for a context, we can just store a url -> event source map globally

changeset-bot[bot] commented 7 months ago

🦋 Changeset detected

Latest commit: 1aa6d3773da990642ed6ebb7dbf7ed6b2d81184b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----------------- | ----- | | @remix-sse/client | Major |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR