@@ -33,6 +33,7 @@ import {
33
33
$eventsProp ,
34
34
addToTree ,
35
35
RENDER_TREE ,
36
+ setBounds ,
36
37
} from './shared' ;
37
38
38
39
// EMPTY DOM PROPS
@@ -43,6 +44,10 @@ const $_className = 'className';
43
44
44
45
let ROOT : Component < any > | null = null ;
45
46
47
+ export function getRoot ( ) {
48
+ return ROOT ;
49
+ }
50
+
46
51
type ModifierFn = (
47
52
element : HTMLElement ,
48
53
...args : unknown [ ]
@@ -296,7 +301,7 @@ export function $_unstableChildComponentWrapper(
296
301
) {
297
302
return component (
298
303
function UnstableChildWrapper ( this : Component < any > ) {
299
- if ( import . meta . env . DEV ) {
304
+ if ( IS_DEV_MODE ) {
300
305
// @ts -expect-error construct signature
301
306
this . debugName = `UnstableChildWrapper-${ unstableWrapperId ++ } ` ;
302
307
}
@@ -308,29 +313,36 @@ export function $_unstableChildComponentWrapper(
308
313
) ;
309
314
}
310
315
311
- function buildGraph ( obj : Record < string , unknown > , root : any , children : any [ ] ) {
312
- const name =
313
- root . debugName || root ?. constructor ?. name || root ?. tagName || 'unknown' ;
314
- if ( children . length === 0 ) {
315
- obj [ name ] = null ;
316
+ if ( IS_DEV_MODE ) {
317
+ function buildGraph (
318
+ obj : Record < string , unknown > ,
319
+ root : any ,
320
+ children : any [ ] ,
321
+ ) {
322
+ const name =
323
+ root . debugName || root ?. constructor ?. name || root ?. tagName || 'unknown' ;
324
+ if ( children . length === 0 ) {
325
+ obj [ name ] = null ;
326
+ return obj ;
327
+ }
328
+ obj [ name ] = children . map ( ( child ) => {
329
+ return buildGraph ( { } , child , RENDER_TREE . get ( child ) ?? [ ] ) ;
330
+ } ) ;
316
331
return obj ;
317
332
}
318
- obj [ name ] = children . map ( ( child ) => {
319
- return buildGraph ( { } , child , RENDER_TREE . get ( child ) ?? [ ] ) ;
320
- } ) ;
321
- return obj ;
322
- }
323
333
324
- function drawTreeToConsole ( ) {
325
- const ref = buildGraph (
326
- { } as Record < string , unknown > ,
327
- ROOT ,
328
- RENDER_TREE . get ( ROOT ! ) ?? [ ] ,
329
- ) ;
330
- console . log ( JSON . stringify ( ref , null , 2 ) ) ;
331
- console . log ( RENDER_TREE ) ;
334
+ function drawTreeToConsole ( ) {
335
+ const ref = buildGraph (
336
+ { } as Record < string , unknown > ,
337
+ ROOT ,
338
+ RENDER_TREE . get ( ROOT ! ) ?? [ ] ,
339
+ ) ;
340
+ console . log ( JSON . stringify ( ref , null , 2 ) ) ;
341
+ console . log ( RENDER_TREE ) ;
342
+ }
343
+ window . drawTreeToConsole = drawTreeToConsole ;
332
344
}
333
- window . drawTreeToConsole = drawTreeToConsole ;
345
+
334
346
// hello, basic component manager
335
347
function component (
336
348
comp : ComponentReturnType | Component ,
@@ -353,12 +365,18 @@ function component(
353
365
// here is workaround for simple components @todo - figure out how to show context-less components in tree
354
366
// for now we don't adding it
355
367
addToTree ( ctx , result . ctx ) ;
368
+ if ( IS_DEV_MODE ) {
369
+ setBounds ( result ) ;
370
+ }
356
371
}
357
372
return result ;
358
373
}
359
374
if ( instance . ctx !== null ) {
360
375
// for now we adding only components with context
361
376
addToTree ( ctx , instance . ctx ) ;
377
+ if ( IS_DEV_MODE ) {
378
+ setBounds ( instance ) ;
379
+ }
362
380
}
363
381
return instance ;
364
382
}
@@ -378,7 +396,7 @@ function mergeComponents(
378
396
const nodes : Array < Node > = [ ] ;
379
397
const contexts : Array < Component > = [ ] ;
380
398
components . forEach ( ( component ) => {
381
- if ( import . meta . env . DEV ) {
399
+ if ( IS_DEV_MODE ) {
382
400
if ( typeof component === 'boolean' || typeof component === 'undefined' ) {
383
401
throw new Error ( `
384
402
Woops, looks like we trying to render boolean or undefined to template, check used helpers.
@@ -583,7 +601,28 @@ const ArgProxyHandler = {
583
601
} ;
584
602
export function $_args ( args : Record < string , unknown > ) {
585
603
if ( IS_GLIMMER_COMPAT_MODE ) {
586
- return new Proxy ( args , ArgProxyHandler ) ;
604
+ if ( IS_DEV_MODE ) {
605
+ const newArgs : Record < string , ( ) => unknown > = { } ;
606
+ Object . keys ( args ) . forEach ( ( key ) => {
607
+ try {
608
+ Object . defineProperty ( newArgs , key , {
609
+ get ( ) {
610
+ if ( ! isFn ( args [ key ] ) ) {
611
+ return args [ key ] ;
612
+ }
613
+ // @ts -expect-error function signature
614
+ return args [ key ] ( ) ;
615
+ } ,
616
+ enumerable : true ,
617
+ } ) ;
618
+ } catch ( e ) {
619
+ console . error ( e ) ;
620
+ }
621
+ } ) ;
622
+ return newArgs ;
623
+ } else {
624
+ return new Proxy ( args , ArgProxyHandler ) ;
625
+ }
587
626
} else {
588
627
return args ;
589
628
}
@@ -613,7 +652,7 @@ export function $_fin(
613
652
}
614
653
} ) ;
615
654
if ( ! isStable ) {
616
- if ( import . meta . env . DEV ) {
655
+ if ( IS_DEV_MODE ) {
617
656
nodes . unshift (
618
657
api . comment ( `unstable root enter node: ${ ctx ?. constructor . name } ` ) ,
619
658
) ;
0 commit comments