File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed
typescript/packages/common-html Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -9,25 +9,26 @@ setDebug(true);
99// setEventSanitizer(...);
1010
1111const text = state ( "text" , "Hello, world!" ) ;
12- const clicks = stream ( "clicks" ) ;
12+ const input = stream < InputEvent > ( "clicks" ) ;
13+
14+ input . sink ( ( event ) => {
15+ console . log ( "input" , event ) ;
16+ const target = event . target as HTMLInputElement | null ;
17+ const value = target ?. value ?? null ;
18+ if ( value !== null ) {
19+ text . send ( value ) ;
20+ }
21+ } ) ;
1322
1423// Build template
1524const renderable = html `
1625 < div class ="container ">
1726 < h1 class ="title "> ${ text } </ h1 >
18- < button onclick = ${ clicks } > Click me </ button >
27+ < input type =" text " oninput = ${ input } value = ${ text } / >
1928 </ div >
2029` ;
2130
2231// Render
2332const dom = render ( renderable ) ;
2433
25- clicks . sink ( ( value ) => {
26- console . log ( "clicks" , value ) ;
27- } ) ;
28-
29- setInterval ( ( ) => {
30- text . send ( `Hello, world! ${ new Date ( ) . toLocaleTimeString ( ) } ` ) ;
31- } , 1000 ) ;
32-
3334document . body . appendChild ( dom ) ;
Original file line number Diff line number Diff line change @@ -112,9 +112,12 @@ const listen = (
112112 } ;
113113} ;
114114
115- const setProp = ( element : HTMLElement , key : string , value : unknown ) => {
115+ const setProp = < T > ( target : T , key : string , value : unknown ) => {
116116 // @ts -ignore - we've validated these via runtime checks
117- element [ key ] = value ;
117+ if ( target [ key ] !== value ) {
118+ // @ts -ignore - we've validated these via runtime checks
119+ target [ key ] = value ;
120+ }
118121} ;
119122
120123const sanitizeScripts = ( node : Node ) : Node | null => {
You can’t perform that action at this time.
0 commit comments