1+ import { render , h } from 'preact'
12
2- import { render , h } from 'preact' ;
3-
4- // h() imports will be added at build time since this file is inlined with the client template
3+ // h() imports will be added at build time since this file is inlined with the client template
54
65const restoreTree = ( type , props = { } ) => {
76 if ( typeof props . children === 'object' ) {
@@ -61,49 +60,53 @@ function mergePropsWithDOM(rootNode, props) {
6160 rootNode . append ( ...scriptNodes )
6261}
6362
63+ init ( )
6464
65- init ( )
66-
67- function init ( ) {
68- if ( customElements . get ( "island-counter" ) ) {
69- return
70- }
71- customElements . define ( "island-counter" , class IslandCounter extends HTMLElement {
72- constructor ( ) {
73- super ( ) ;
65+ function init ( ) {
66+ if ( customElements . get ( 'island-counter' ) ) {
67+ return
68+ }
69+ customElements . define (
70+ 'island-counter' ,
71+ class IslandCounter extends HTMLElement {
72+ constructor ( ) {
73+ super ( )
7474 }
75-
75+
7676 async connectedCallback ( ) {
77- const c = await import ( "/Users/sid/code/adex/playground/src/components/counter.tsx" ) ;
78- const usableComponent = c [ "Counter" ]
79- const props = JSON . parse ( this . dataset . props || '{}' ) ;
80- this . baseProps = props
81- this . component = usableComponent
82- this . renderOnView ( { threshold :0.2 } )
77+ const c = await import (
78+ '/Users/sid/code/adex/playground/src/components/counter.tsx'
79+ )
80+ const usableComponent = c [ 'Counter' ]
81+ const props = JSON . parse ( this . dataset . props || '{}' )
82+ this . baseProps = props
83+ this . component = usableComponent
84+ this . renderOnView ( { threshold : 0.2 } )
8385 }
84-
85- renderOnView ( { threshold} = { } ) {
86+
87+ renderOnView ( { threshold } = { } ) {
8688 const options = {
8789 root : null ,
8890 threshold,
89- } ;
90-
91- const self = this ;
92-
93- const callback = function ( entries , observer ) {
94- entries . forEach ( ( entry ) => {
95- if ( ! entry . isIntersecting ) return
91+ }
92+
93+ const self = this
94+
95+ const callback = function ( entries , observer ) {
96+ entries . forEach ( entry => {
97+ if ( ! entry . isIntersecting ) return
9698 self . renderIsland ( )
97- } ) ;
99+ } )
98100 }
99-
100- let observer = new IntersectionObserver ( callback , options ) ;
101- observer . observe ( this ) ;
101+
102+ let observer = new IntersectionObserver ( callback , options )
103+ observer . observe ( this )
102104 }
103-
104- renderIsland ( ) {
105- mergePropsWithDOM ( this , this . baseProps ) ;
105+
106+ renderIsland ( ) {
107+ mergePropsWithDOM ( this , this . baseProps )
106108 render ( restoreTree ( this . component , this . baseProps ) , this , undefined )
107109 }
108- } )
109- }
110+ }
111+ )
112+ }
0 commit comments