1
+ import { render , h } from 'preact'
1
2
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
5
4
6
5
const restoreTree = ( type , props = { } ) => {
7
6
if ( typeof props . children === 'object' ) {
@@ -61,49 +60,53 @@ function mergePropsWithDOM(rootNode, props) {
61
60
rootNode . append ( ...scriptNodes )
62
61
}
63
62
63
+ init ( )
64
64
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 ( )
74
74
}
75
-
75
+
76
76
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 } )
83
85
}
84
-
85
- renderOnView ( { threshold} = { } ) {
86
+
87
+ renderOnView ( { threshold } = { } ) {
86
88
const options = {
87
89
root : null ,
88
90
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
96
98
self . renderIsland ( )
97
- } ) ;
99
+ } )
98
100
}
99
-
100
- let observer = new IntersectionObserver ( callback , options ) ;
101
- observer . observe ( this ) ;
101
+
102
+ let observer = new IntersectionObserver ( callback , options )
103
+ observer . observe ( this )
102
104
}
103
-
104
- renderIsland ( ) {
105
- mergePropsWithDOM ( this , this . baseProps ) ;
105
+
106
+ renderIsland ( ) {
107
+ mergePropsWithDOM ( this , this . baseProps )
106
108
render ( restoreTree ( this . component , this . baseProps ) , this , undefined )
107
109
}
108
- } )
109
- }
110
+ }
111
+ )
112
+ }
0 commit comments