Skip to content

Commit 6e2df8d

Browse files
committed
moved init
1 parent 8019751 commit 6e2df8d

File tree

1 file changed

+31
-43
lines changed

1 file changed

+31
-43
lines changed

docs/telegram-bot-playground/index.html

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,24 @@
1212
<link rel="stylesheet" href="styles.css?v=oq5lin">
1313
</head>
1414

15-
<body
16-
x-data="{
15+
<body x-data="{
1716
selected_example: 'empty.ts',
1817
botUpdates: [],
1918
botState: {
2019
name: 'nameless',
2120
status: 'idle',
2221
token: ''
2322
}
24-
}"
25-
x-init="
26-
await playground.start();
27-
playground.onCodeChange(() => {
28-
playground.runBot(botState);
29-
});
30-
playground.worker.onmessage = (e) => {
31-
console.log('got message from worker', e?.data);
32-
if (!e?.data) return;
33-
if (e.data.botState) {
34-
Object.assign(botState, e.data.botState)
35-
}
36-
botUpdates.push(e.data);
37-
console.log('Scrolling', $refs.updates.scrollHeight);
38-
$nextTick(() => { $refs.updates.scrollTop = $refs.updates.scrollHeight })
39-
};
40-
"
41-
>
23+
}">
4224

4325
<h1>Telegram Bot Playground 🤖 </h1>
4426

4527
<div style="display: flex; gap: 20px; justify-content: center;">
46-
28+
4729
<label>
4830
Bot token
49-
<input
50-
type="text"
51-
x-model="botState.token"
52-
placeholder="your token"
53-
@input.debounce.500ms="playground.checkToken(botState)"
54-
>
31+
<input type="text" x-model="botState.token" placeholder="your token"
32+
@input.debounce.500ms="playground.checkToken(botState)">
5533
</label>
5634

5735
<label>Bot name: <span x-text="botState.name"></span></label>
@@ -62,33 +40,43 @@ <h1>Telegram Bot Playground 🤖 </h1>
6240
<div style="display: flex; align-items: start;">
6341
<label>
6442
Select example
65-
<select
66-
67-
x-model="selected_example"
68-
@change="playground.loadExample(selected_example)"
69-
>
70-
<option value="empty.ts">Empty</option>
71-
<option value="command.ts">Command Bot</option>
72-
<option value="file.ts">File Bot</option>
73-
</select>
43+
<select x-model="selected_example" @change="playground.loadExample(selected_example)">
44+
<option value="empty.ts">Empty</option>
45+
<option value="command.ts">Command Bot</option>
46+
<option value="file.ts">File Bot</option>
47+
</select>
7448
</label>
7549

7650
</div>
7751

7852
<div class="flex-container">
7953
<div id="container" x-cloak></div>
80-
<div
81-
id="worker-updates"
82-
x-ref="updates"
83-
>
84-
<template
85-
x-for="update in botUpdates" :key="update.id"
86-
>
54+
<div id="worker-updates" x-ref="updates">
55+
<template x-for="update in botUpdates" :key="update.id">
8756
<div x-text="JSON.stringify(update, undefined, 2)"></div>
8857
</template>
8958
</div>
9059
</div>
9160

61+
<script>
62+
document.addEventListener('alpine:initialized', async () => {
63+
await playground.start();
64+
playground.onCodeChange(() => {
65+
playground.runBot(botState);
66+
});
67+
playground.worker.onmessage = (e) => {
68+
console.log('got message from worker', e?.data);
69+
if (!e?.data) return;
70+
if (e.data.botState) {
71+
Object.assign(botState, e.data.botState)
72+
}
73+
botUpdates.push(e.data);
74+
console.log('Scrolling', $refs.updates.scrollHeight);
75+
$nextTick(() => { $refs.updates.scrollTop = $refs.updates.scrollHeight })
76+
};
77+
})
78+
</script>
79+
9280
</body>
9381

9482
</html>

0 commit comments

Comments
 (0)