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
45class 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
1213class 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
3336export 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}
0 commit comments