Skip to content

Commit ce7995e

Browse files
committed
chore(examples/basic): launch example
1 parent 41c8869 commit ce7995e

File tree

3 files changed

+66
-14
lines changed

3 files changed

+66
-14
lines changed

examples/basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"preview": "vite preview"
99
},
1010
"dependencies": {
11+
"@zero-dependency/dom": "^0.10.0",
1112
"fireworks-js": "workspace:*"
1213
},
1314
"devDependencies": {

examples/basic/src/index.ts

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,62 @@
11
import { Fireworks } from 'fireworks-js'
2+
import { el } from '@zero-dependency/dom'
23
import './style.css'
34

45
const app = document.querySelector<HTMLDivElement>('#app')!
56
const fireworks = new Fireworks(app)
67

7-
const button = document.createElement('button')
8-
button.textContent = 'Start'
9-
button.style.position = 'absolute'
10-
button.style.zIndex = '999'
11-
button.addEventListener('click', () => {
12-
fireworks.start()
13-
stopFireworks(fireworks)
8+
const start = el(
9+
'button',
10+
{
11+
onclick: () => {
12+
fireworks.start()
13+
}
14+
},
15+
'Start'
16+
)
17+
18+
const stop = el(
19+
'button',
20+
{
21+
onclick: () => {
22+
fireworks.waitStop()
23+
}
24+
},
25+
'Stop'
26+
)
27+
28+
const launch = el(
29+
'button',
30+
{
31+
onclick: () => {
32+
fireworks.launch(Number(fires.value))
33+
}
34+
},
35+
'Launch'
36+
)
37+
38+
const fires = el('input', {
39+
value: '1',
40+
type: 'number',
41+
placeholder: 'count',
42+
style: {
43+
width: '2rem'
44+
}
1445
})
1546

16-
document.body.appendChild(button)
47+
const buttons = el(
48+
'div',
49+
{
50+
style: {
51+
position: 'absolute',
52+
display: 'flex',
53+
gap: '4px'
54+
}
55+
},
56+
start,
57+
stop,
58+
launch,
59+
fires
60+
)
1761

18-
async function stopFireworks(fireworks: Fireworks) {
19-
console.time()
20-
await new Promise((resolve) => setTimeout(resolve, 2000))
21-
await fireworks.waitStop()
22-
console.timeEnd()
23-
}
62+
document.body.appendChild(buttons)

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)