datastar-ssegen 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +36 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
## Overview
|
7
7
|
|
8
|
-
The `datastar-ssegen` is a backend JavaScript module designed to generate Server-Sent Events (SSE) for connected [Datastar](https://data-star.dev/) clients. It supports popular server frameworks such as Express.js, Node.js, and Hyper Express.js, and Bun.
|
8
|
+
The `datastar-ssegen` is a backend JavaScript module designed to generate Server-Sent Events (SSE) for connected [Datastar](https://data-star.dev/) clients. It supports popular server frameworks such as Express.js, Node.js, and Hyper Express.js, and Bun and Elysia.
|
9
9
|
|
10
10
|
This package is engineered to integrate tightly with request and response objects of these backend frameworks, enabling efficient and reactive web application development.
|
11
11
|
|
@@ -81,9 +81,43 @@ Here's a simple HTML page to interact with the server:
|
|
81
81
|
```
|
82
82
|
|
83
83
|
|
84
|
+
### Quick Start Example with Elysia
|
85
|
+
|
86
|
+
```javascript
|
87
|
+
import { Elysia } from "elysia";
|
88
|
+
import { html } from "@elysiajs/html";
|
89
|
+
import { ServerSentEventGenerator } from "datastar-ssegen";
|
90
|
+
|
91
|
+
const app = new Elysia()
|
92
|
+
.use(html())
|
93
|
+
.get(
|
94
|
+
"/",
|
95
|
+
() =>
|
96
|
+
`<html>
|
97
|
+
<head>
|
98
|
+
<script type="module" src="https://cdn.jsdelivr.net/gh/starfederation/datastar/bundles/datastar.js"></script>
|
99
|
+
</head>
|
100
|
+
<body data-on-load="sse('/feed')">
|
101
|
+
<div id="hello">???</div>
|
102
|
+
</body>
|
103
|
+
</html>`
|
104
|
+
)
|
105
|
+
.get("/feed", function* ({ request, set }) {
|
106
|
+
const sse = ServerSentEventGenerator(request);
|
107
|
+
set.headers = sse.headers;
|
108
|
+
yield sse.MergeFragments(`<div id="hello">Hello!</div>`);
|
109
|
+
})
|
110
|
+
|
111
|
+
.listen(3000);
|
112
|
+
|
113
|
+
console.log(
|
114
|
+
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
|
115
|
+
);
|
116
|
+
```
|
117
|
+
|
84
118
|
### Quick Start Example with Bun
|
85
119
|
|
86
|
-
Using this with Bun requires you to create the response. Below is an example of how to integrate the datastar-ssegen with a Stream
|
120
|
+
Using this with Bun requires you to create the response. Below is an example of how to integrate the datastar-ssegen with a Stream:
|
87
121
|
|
88
122
|
```javascript
|
89
123
|
import { ServerSentEventGenerator } from "../index.js";
|