1- import {
2- component$ ,
1+ import {
2+ component$ ,
33 useStore ,
4- useSignal ,
5- useTask$ ,
6- useComputed$ ,
4+ useSignal ,
5+ useTask$ ,
6+ useComputed$ ,
77 $ ,
88 useContext ,
99 useContextProvider ,
@@ -22,11 +22,23 @@ import {
2222 useServerData ,
2323 useErrorBoundary ,
2424} from '@qwik.dev/core' ;
25- import { _getDomContainer , isServer , useVisibleTask$ } from '@qwik.dev/core/internal' ;
25+ import {
26+ _getDomContainer ,
27+ isServer ,
28+ useVisibleTask$ ,
29+ } from '@qwik.dev/core/internal' ;
2630import type { QRL , Signal } from '@qwik.dev/core' ;
27- import { useLocation , useNavigate , Link , useContent , useDocumentHead } from '@qwik.dev/router' ;
31+ import {
32+ useLocation ,
33+ useNavigate ,
34+ Link ,
35+ useContent ,
36+ useDocumentHead ,
37+ } from '@qwik.dev/router' ;
2838import { useDebouncer } from './debounce' ;
29- const ButtonContext = createContextId < { theme : string ; size : string } > ( 'button-context' ) ;
39+ const ButtonContext = createContextId < { theme : string ; size : string } > (
40+ 'button-context' ,
41+ ) ;
3042
3143interface ButtonProps {
3244 class ?: string ;
@@ -36,13 +48,13 @@ interface ButtonProps {
3648
3749export default component$ < ButtonProps > ( ( props ) => {
3850 const { class : className = '' , onClick$ } = props ;
39- const testValue2 = props . testValue
40- console . log ( 'testValue' , testValue2 )
51+ const testValue2 = props . testValue ;
52+ console . log ( 'testValue' , testValue2 ) ;
4153 const store = useStore ( {
4254 count : 0 ,
43- dd :12 ,
55+ dd : 12 ,
4456 cc : 33 ,
45- aa : [ 1 , 2 , 3 ]
57+ aa : [ 1 , 2 , 3 ] ,
4658 } ) ;
4759 const signal = useSignal < any > ( '111' ) ;
4860 const constantValue = useConstant ( ( ) => 'CONST' ) ;
@@ -53,23 +65,21 @@ export default component$<ButtonProps>((props) => {
5365 const content = useContent ( ) ;
5466 const head = useDocumentHead ( ) ;
5567
56-
57-
5868 useTask$ ( ( { track } ) => {
5969 track ( ( ) => store . count ) ;
60- signal . value = '33333'
61- } )
70+ signal . value = '33333' ;
71+ } ) ;
6272
6373 // eslint-disable-next-line qwik/no-use-visible-task
6474 useVisibleTask$ ( ( { track } ) => {
6575 track ( ( ) => store . count ) ;
66- signal . value = '2227'
67- } )
76+ signal . value = '2227' ;
77+ } ) ;
6878
6979 const qwikContainer = useComputed$ ( ( ) => {
7080 try {
71- if ( isServer ) {
72- return null
81+ if ( isServer ) {
82+ return null ;
7383 }
7484 const htmlElement = document . documentElement ;
7585 return _getDomContainer ( htmlElement ) ;
@@ -79,37 +89,46 @@ export default component$<ButtonProps>((props) => {
7989 }
8090 } ) ;
8191
82- const asyncComputedValue = useAsyncComputed$ ( ( { track } ) =>
92+ const asyncComputedValue = useAsyncComputed$ ( ( { track } ) =>
8393 Promise . resolve ( track ( signal ) + 3 ) ,
8494 ) ;
85-
95+
8696 useContextProvider ( ButtonContext , {
8797 theme : 'primary' ,
88- size : 'large'
98+ size : 'large' ,
8999 } ) ;
90100
91101 const context = useContext ( ButtonContext ) ;
92102
93103 const buttonId = useId ( ) ;
94104
95- useOnDocument ( 'keydown' , $ ( ( ) => {
96- console . log ( 'Document keydown event' ) ;
97- } ) ) ;
105+ useOnDocument (
106+ 'keydown' ,
107+ $ ( ( ) => {
108+ console . log ( 'Document keydown event' ) ;
109+ } ) ,
110+ ) ;
98111
99- useOnWindow ( 'resize' , $ ( ( ) => {
100- console . log ( 'Window resized' ) ;
101- } ) ) ;
112+ useOnWindow (
113+ 'resize' ,
114+ $ ( ( ) => {
115+ console . log ( 'Window resized' ) ;
116+ } ) ,
117+ ) ;
102118
103- useOn ( 'click' , $ ( ( ) => {
104- console . log ( 'Host clicked' ) ;
105- } ) ) ;
119+ useOn (
120+ 'click' ,
121+ $ ( ( ) => {
122+ console . log ( 'Host clicked' ) ;
123+ } ) ,
124+ ) ;
106125
107126 const resourceData = useResource$ ( async ( { track } ) => {
108127 track ( ( ) => store . count ) ;
109- await new Promise ( resolve => setTimeout ( resolve , 200 ) ) ;
128+ await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ;
110129 return {
111130 message : `Resource data for count: ${ store . count } ` ,
112- timestamp : Date . now ( )
131+ timestamp : Date . now ( ) ,
113132 } ;
114133 } ) ;
115134
@@ -118,7 +137,7 @@ export default component$<ButtonProps>((props) => {
118137 update : ( current : { n : number } ) => {
119138 current . n = store . count ;
120139 return current ;
121- }
140+ } ,
122141 } ) ) ;
123142
124143 useStyles$ ( `
@@ -150,18 +169,20 @@ export default component$<ButtonProps>((props) => {
150169 $ ( ( value : string ) => {
151170 signal . value = value ;
152171 } ) ,
153- 1000
172+ 1000 ,
173+ ) ;
174+
175+ useDebouncer (
176+ $ ( ( value : string ) => {
177+ signal . value = value ;
178+ } ) ,
179+ 1000 ,
154180 ) ;
155-
156- useDebouncer ( $ ( ( value : string ) => {
157- signal . value = value ;
158- } ) ,
159- 1000 )
160181
161182 const handleClick = $ ( async ( ) => {
162183 store . count ++ ;
163184 console . log ( 'Button clicked! Count:' , store . count ) ;
164- debounce ( store . count )
185+ debounce ( store . count ) ;
165186 if ( onClick$ ) {
166187 await onClick$ ( ) ;
167188 }
@@ -171,35 +192,47 @@ export default component$<ButtonProps>((props) => {
171192
172193 return (
173194 < div >
174- < button
195+ < button
175196 id = { buttonId }
176197 class = { `${ className } custom-button scoped-button` }
177198 onClick$ = { handleClick }
178199 >
179- Click me { store . count } { signal . value } { qwikContainer . value ?. qManifestHash }
200+ Click me { store . count }
201+ { signal . value }
202+ { qwikContainer . value ?. qManifestHash }
180203 </ button >
181- < button
204+ < button
182205 class = { `custom-button scoped-button` }
183206 style = "margin-left: 8px"
184207 onClick$ = { handleGoAbout }
185208 >
186209 Go /about
187210 </ button >
188- < Link href = "/blog" class = { `scoped-button` } style = "margin-left: 8px; padding: 8px 16px; display: inline-block; text-decoration: none;" >
211+ < Link
212+ href = "/blog"
213+ class = { `scoped-button` }
214+ style = "margin-left: 8px; padding: 8px 16px; display: inline-block; text-decoration: none;"
215+ >
189216 Go /blog
190217 </ Link >
191-
218+
192219 < div style = "margin-top: 10px; font-size: 12px; color: #666;" >
193220 < div > Current Path: { location . url . pathname } </ div >
194221 < div > Is Navigating: { location . isNavigating ? 'true' : 'false' } </ div >
195222 < div > Params: { JSON . stringify ( location . params ) } </ div >
196- < div > Prev URL: { location . prevUrl ? location . prevUrl . pathname : '—' } </ div >
223+ < div >
224+ Prev URL: { location . prevUrl ? location . prevUrl . pathname : '—' }
225+ </ div >
197226 < div > Head Title: { head . title } </ div >
198227 < div > Head Metas: { head . meta . length } </ div >
199228 < div > Content Menu: { content . menu ? 'yes' : 'no' } </ div >
200- < div > Content Headings: { content . headings ? content . headings . length : 0 } </ div >
229+ < div >
230+ Content Headings: { content . headings ? content . headings . length : 0 }
231+ </ div >
201232 < div > Async Computed: { asyncComputedValue . value } </ div >
202- < div > Context: { context . theme } - { context . size } </ div >
233+ < div >
234+ Context: { context . theme } - { context . size }
235+ </ div >
203236 < div > Button ID: { buttonId } </ div >
204237 < div > Constant: { constantValue } </ div >
205238 { errorBoundary . error && < div > Error captured</ div > }
@@ -211,7 +244,9 @@ export default component$<ButtonProps>((props) => {
211244 onResolved = { ( data ) => < div > Resource: { data . message } </ div > }
212245 onRejected = { ( error ) => < div > Error: { error . message } </ div > }
213246 />
214- < div > Count: { store . count } , Signal: { signal . value } </ div >
247+ < div >
248+ Count: { store . count } , Signal: { signal . value }
249+ </ div >
215250 </ div >
216251 </ div >
217252 ) ;
0 commit comments