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

Version Packages #21

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .changeset/kind-olives-crash.md

This file was deleted.

20 changes: 0 additions & 20 deletions .changeset/little-cobras-attack.md

This file was deleted.

32 changes: 0 additions & 32 deletions .changeset/modern-rocks-check.md

This file was deleted.

41 changes: 0 additions & 41 deletions .changeset/tall-crews-return.md

This file was deleted.

80 changes: 80 additions & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# @remix-sse/client

## 1.0.0

### Major Changes

- 08b640b: Changes the API for `useSubscribe` to make an eventKey default to 'message'

Using the library myself in a few projects, I have found that I don't usually need to send multiple events from the same emitter, and one eventKey usually suffices. This change will make it more ergonomic for single event emitters, while remaining flexible for multi event emitters

## How to migrate

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

Or if you want use the default `eventKey: 'message'` you can omit it entirely

```.tsx
const data = useSubscribe('/emitter')
```

- 7178870: Split up the single `remix-sse` package into 2 seperate packages `@remix-sse/client` and `@remix-sse/server`

## Why

Exporting both the client and server code from a single package has never sat well with me, at the start I got by releasing a single package: remix-sse for server code and remix-sse/client for client code.

This works fine if you are trasnpiling CommonJS imports, but at some point recently create-remix has started every project with type: "module" (ES Modules).

So this made our import paths quite ugly:
`remix-sse/client/index.js` -

Not to mention this uglier syntax was less discoverable now by language servers.

## How to migrate

- Find and replace `import 'remix-sse/client'` -> `import '@remix-sse/client'`
- Find and replace `import 'remix-sse'` -> `import '@remix-sse'`

- 3159987: - `useSubscribe` changed to take an `EventSource`

- new `useEventStream` hook to be superseed `useSubscribe` as the ergonomic way of listening to events
- removed `useEventSource`
- removed `RemixSseProvider`

# No more boilerplate

I wasn't happy with the amount of boilerplate even after making several changes like [making the eventKey default to 'message'](https://github.com/dan-cooke/remix-sse/commit/08b640be243af59bd62dbff15f93ee6a09d3fb71)

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`

```diff
--- 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.

```.tsx

const data = useEventStream('/emitter')

```

### Removed the context and useEventStream

No need for a context, we can just store a url -> event source map globally
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remix-sse/client",
"version": "0.0.0",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
53 changes: 53 additions & 0 deletions packages/server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# @remix-sse/server

## 1.0.0

### Major Changes

- 7178870: Split up the single `remix-sse` package into 2 seperate packages `@remix-sse/client` and `@remix-sse/server`

## Why

Exporting both the client and server code from a single package has never sat well with me, at the start I got by releasing a single package: remix-sse for server code and remix-sse/client for client code.

This works fine if you are trasnpiling CommonJS imports, but at some point recently create-remix has started every project with type: "module" (ES Modules).

So this made our import paths quite ugly:
`remix-sse/client/index.js` -

Not to mention this uglier syntax was less discoverable now by language servers.

## How to migrate

- Find and replace `import 'remix-sse/client'` -> `import '@remix-sse/client'`
- Find and replace `import 'remix-sse'` -> `import '@remix-sse'`

- 08b640b: Changes the API of the `EventStream` send function to make the eventKey default to 'message'

Using the library myself in a few projects, I have found that I don't usually need to send multiple events from the same emitter, and one eventKey usually suffices. This change will make it more ergonomic for single event emitters, while remaining flexible for multi event emitters

## How to migrate

The first argument of send is now just the data string you wish to send.

- If you want to allow multiple events from the same emitter you can specify an `eventKey` in the second argument
- Otherwise you can just omit the eventKey all together

```diff

export const loader: LoaderFunction = ({ request }) => {
return new EventStream(request, (send) => {
let gIndex = 0;
let g = setInterval(() => {
gIndex += 1;
--- send('message', JSON.stringify({ hello: 'world', index: gIndex }));
+++ send(JSON.stringify({ hello: 'world', index: gIndex }));
}, 1000);


return async () => {
clearInterval(g);
};
});
};
```
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remix-sse/server",
"version": "0.0.0",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Loading