42 lines
1.2 KiB
HTML
42 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<script type="module" defer
|
|
src="https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.0-RC.6/bundles/datastar.js"></script>
|
|
<title>Document</title>
|
|
<link rel="stylesheet" href="main.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div data-signals:count="'START'" data-text="$count"></div>
|
|
<script>
|
|
let counter = 0;
|
|
|
|
// helper function that activates the PatchSignals
|
|
// watcher plugin to simulate a completed fetch request
|
|
const patchSignals = (count) => {
|
|
// a simulated `datastar-patch-signals` event
|
|
const detail = {
|
|
type: "datastar-patch-signals",
|
|
argsRaw: {
|
|
signals: JSON.stringify({ count })
|
|
}
|
|
};
|
|
|
|
// trigger the SSEEventWatcher by simulating a `datastar-fetch` event
|
|
document.dispatchEvent(new CustomEvent("datastar-fetch", { detail }));
|
|
};
|
|
|
|
setInterval(() => {
|
|
patchSignals(counter);
|
|
counter++;
|
|
}, 250);
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html> |