Skip to content

Commit 4f08aaf

Browse files
committed
chore(examples): update jsx
1 parent 786d935 commit 4f08aaf

File tree

4 files changed

+47
-47
lines changed

4 files changed

+47
-47
lines changed

examples/jsx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"vite-userscript-plugin": "workspace:*"
1414
},
1515
"dependencies": {
16-
"redom": "^3.29.0",
16+
"redom": "link:../../../vite-redom-jsx/packages/redom/",
1717
"redom-jsx": "^1.2.1"
1818
}
1919
}

examples/jsx/src/App.tsx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
import { Router, RedomComponent, mount, unmount, router } from 'redom'
2-
import { Counter } from './Counter'
1+
import { Router, mount, router, unmount } from 'redom'
2+
import type { RedomComponent, RedomEl } from 'redom'
3+
import { Counter } from './Counter.js'
34

45
class H1 implements RedomComponent {
5-
public el: Router
6+
public el: RedomEl
67

78
constructor() {
8-
<span this="el">hello</span>
9+
;<span this="el">hello</span>
910
}
1011
}
1112

1213
class H2 implements RedomComponent {
13-
public el: Router
14+
public el: RedomEl
1415

1516
constructor() {
16-
<span this="el">world</span>
17+
;<span this="el">world</span>
1718
}
1819
}
1920

20-
class Heading implements RedomComponent {
21+
class Heading {
2122
public el: Router
2223

2324
constructor() {
24-
this.el = router('.heading', {
25+
this.el = router('p.heading', {
2526
h1: H1,
2627
h2: H2
27-
}, 'h1')
28+
})
29+
30+
this.el.update('h1')
2831
}
2932
}
3033

31-
const list = Array.from({ length: 10 }, () => Math.random())
34+
const list = Array.from({ length: 5 }, () => Math.random())
3235

3336
export class App implements RedomComponent {
34-
public el: HTMLElement
37+
public el: RedomEl
3538
public counter: RedomComponent
3639
public button: HTMLElement
3740
public router: Router
41+
public toggle = true
3842

3943
constructor() {
4044
this.render()
@@ -49,7 +53,6 @@ export class App implements RedomComponent {
4953
<button
5054
this="button"
5155
onclick={() => {
52-
// @ts-ignore
5356
if (this.counter.el.__redom_mounted) {
5457
unmount(this.el, this.counter)
5558
} else {
@@ -64,20 +67,24 @@ export class App implements RedomComponent {
6467
veniam id consequatur, dolor recusandae minima dolore ab eius sunt quo
6568
totam quasi nam? Cum voluptate et id porro odit!
6669
</p>
67-
{list.map((value) => {
68-
return <p>{value}</p>
69-
})}
70+
{list.map((value) => (
71+
<p>{value}</p>
72+
))}
7073
<a
7174
href="https://google.com"
7275
target="_blank"
7376
>
7477
This is link
7578
</a>
7679
<Heading this="router" />
77-
<button onclick={() => {
78-
// @ts-ignore
79-
this.router.el.update(Math.random() < .5 ? 'h1' : 'h2')
80-
}}>toggle</button>
80+
<button
81+
onclick={() => {
82+
this.toggle = !this.toggle
83+
this.router.el.update!(this.toggle ? 'h1' : 'h2')
84+
}}
85+
>
86+
toggle
87+
</button>
8188
</div>
8289
}
8390
}

examples/jsx/src/Counter.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import type { RedomComponent } from 'redom'
2-
3-
type RedomProps<T extends Record<string, any>> = {
4-
this?: string
5-
} & T
1+
import type { RedomComponent, RedomEl, RedomProps } from 'redom'
62

73
interface Props {
84
initialValue?: number
95
}
106

117
export class Counter implements RedomComponent {
12-
public el: HTMLElement
8+
public el: RedomEl
139

1410
private counter: number
1511
private initialCounter: number

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)