Skip to content

Commit 786d935

Browse files
committed
chore: update jsx example
1 parent 75d7dc5 commit 786d935

File tree

4 files changed

+76
-32
lines changed

4 files changed

+76
-32
lines changed

examples/jsx/src/App.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1-
import { RedomComponent, mount, unmount } from 'redom'
1+
import { Router, RedomComponent, mount, unmount, router } from 'redom'
22
import { Counter } from './Counter'
33

4+
class H1 implements RedomComponent {
5+
public el: Router
6+
7+
constructor() {
8+
<span this="el">hello</span>
9+
}
10+
}
11+
12+
class H2 implements RedomComponent {
13+
public el: Router
14+
15+
constructor() {
16+
<span this="el">world</span>
17+
}
18+
}
19+
20+
class Heading implements RedomComponent {
21+
public el: Router
22+
23+
constructor() {
24+
this.el = router('.heading', {
25+
h1: H1,
26+
h2: H2
27+
}, 'h1')
28+
}
29+
}
30+
31+
const list = Array.from({ length: 10 }, () => Math.random())
32+
433
export class App implements RedomComponent {
534
public el: HTMLElement
635
public counter: RedomComponent
736
public button: HTMLElement
37+
public router: Router
838

939
constructor() {
1040
this.render()
@@ -14,7 +44,7 @@ export class App implements RedomComponent {
1444
;<div this="el">
1545
<Counter
1646
this="counter"
17-
initialCounter={10}
47+
initialValue={-10}
1848
/>
1949
<button
2050
this="button"
@@ -34,12 +64,20 @@ export class App implements RedomComponent {
3464
veniam id consequatur, dolor recusandae minima dolore ab eius sunt quo
3565
totam quasi nam? Cum voluptate et id porro odit!
3666
</p>
67+
{list.map((value) => {
68+
return <p>{value}</p>
69+
})}
3770
<a
3871
href="https://google.com"
3972
target="_blank"
4073
>
4174
This is link
4275
</a>
76+
<Heading this="router" />
77+
<button onclick={() => {
78+
// @ts-ignore
79+
this.router.el.update(Math.random() < .5 ? 'h1' : 'h2')
80+
}}>toggle</button>
4381
</div>
4482
}
4583
}

examples/jsx/src/Counter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type RedomProps<T extends Record<string, any>> = {
55
} & T
66

77
interface Props {
8-
initialCounter?: number
8+
initialValue?: number
99
}
1010

1111
export class Counter implements RedomComponent {
@@ -15,8 +15,8 @@ export class Counter implements RedomComponent {
1515
private initialCounter: number
1616
private interval: ReturnType<typeof setInterval>
1717

18-
constructor({ initialCounter }: RedomProps<Props>) {
19-
this.initialCounter = initialCounter ?? 0
18+
constructor({ initialValue }: RedomProps<Props>) {
19+
this.initialCounter = initialValue ?? 0
2020
this.counter = this.initialCounter
2121
this.render()
2222
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
"@types/node": "^18.7.13",
5656
"@types/websocket": "^1.0.5",
5757
"@vitest/ui": "^0.22.1",
58-
"tsup": "^6.2.2",
58+
"tsup": "^6.2.3",
5959
"turbo": "^1.4.3",
60-
"typescript": "^4.7.4",
60+
"typescript": "^4.8.2",
6161
"vite": "^3.0.9",
6262
"vite-plugin-dts": "^1.4.1",
6363
"vitest": "^0.22.1"

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)