-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
41 lines (38 loc) · 1.35 KB
/
Copy pathmain.js
File metadata and controls
41 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Async, createSignal } from "../../src/index.js";
import { AsyncStream } from "../../src/stream.js";
Async.use({
signal: {
streamingDemo: createSignal({
title: "Streamed Keyboard",
selected: false
})
},
handler: {
"streamingDemo.streamProduct"() {
this.loader.swap(
"product",
`
<article>
<h1 signal:text="streamingDemo.title"></h1>
<button type="button" on:click="streamingDemo.select" class:selected="streamingDemo.selected">
Select
</button>
</article>
`
);
},
"streamingDemo.select"() {
this.signals.set("streamingDemo.selected", true);
}
}
});
const runtime = Async.start({ root: document.body, router: false });
// Platform adapter: replay the wire patches the server emitted as inline JSON
// scripts. Each call resolves the shared per-loader receiver, so sequence
// dedup, reveal buffering, and error settling work across separate scripts —
// no receiver instance needs to be threaded through the page. Reveal metadata
// comes from the DOM (async:reveal / reveal-order / reveal-tail); the patches
// carry only boundary, seq, and html or error.
for (const script of document.querySelectorAll('script[type="application/json"][data-stream-patch]')) {
await AsyncStream.applyScript(script, { runtime });
}