@@ -30,8 +30,10 @@ import {
3030 disconnectingEvent ,
3131} from './events' ;
3232
33- const changeTask = Symbol ( 'ChangeTask' ) ;
34- const changeRequest = Symbol ( 'ChangeRequest' ) ;
33+ const task = Symbol ( 'Task' ) ;
34+ const create = Symbol ( 'Create' ) ;
35+ const setup = Symbol ( 'Setup' ) ;
36+ const update = Symbol ( 'Update' ) ;
3537
3638export default class Component extends HTMLElement {
3739
@@ -47,7 +49,7 @@ export default class Component extends HTMLElement {
4749 tag = dash ( tag ) ;
4850 define ( tag , this ) ;
4951 const instance = document . createElement ( tag ) ;
50- await ( instance as Component ) [ changeTask ] ;
52+ await ( instance as Component ) [ create ] ;
5153 return instance ;
5254 }
5355
@@ -65,18 +67,17 @@ export default class Component extends HTMLElement {
6567 declare disconnected ?: ( context : Record < any , any > ) => void | Promise < void > ;
6668 declare attribute ?: ( name : string , oldValue : string , newValue : string ) => void | Promise < void > ;
6769
68- #isCreatingOrCreated: boolean = false ;
69-
7070 #context: Record < any , any > = { } ;
7171 #root: Element | ShadowRoot ;
7272
7373 #marker: string = '' ;
7474 #actions: Actions = [ ] ;
7575 #expressions: Expressions = [ ] ;
7676
77- #changeBusy: boolean = false ;
78- #changeRestart: boolean = false ;
79- [ changeTask ] : Promise < void > = Promise . resolve ( ) ;
77+ #busy: boolean = false ;
78+ #restart: boolean = false ;
79+ #created: boolean = false ;
80+ [ task ] : Promise < void > = Promise . resolve ( ) ;
8081
8182 constructor ( ) {
8283 super ( ) ;
@@ -104,25 +105,8 @@ export default class Component extends HTMLElement {
104105 }
105106
106107 async connectedCallback ( ) {
107-
108- if ( ! this . #isCreatingOrCreated) {
109- this . #isCreatingOrCreated = true ;
110- this . #changeBusy = true ;
111-
112- await this . #setup( ) ;
113-
114- this . dispatchEvent ( creatingEvent ) ;
115- await this . created ?.( this . #context) ;
116- this . dispatchEvent ( createdEvent ) ;
117-
118- this . dispatchEvent ( connectingEvent ) ;
119- await this . connected ?.( this . #context) ?. catch ( console . error ) ;
120- this . dispatchEvent ( connectedEvent ) ;
121-
122- this . #changeBusy = false ;
123- this . #changeRestart = false ;
124- await this [ changeRequest ] ( ) ;
125-
108+ if ( ! this . #created) {
109+ await this [ create ] ( ) ;
126110 } else {
127111 this . dispatchEvent ( connectingEvent ) ;
128112 await this . connected ?.( this . #context) ?. catch ( console . error ) ;
@@ -136,16 +120,35 @@ export default class Component extends HTMLElement {
136120 this . dispatchEvent ( disconnectedEvent ) ;
137121 }
138122
139- async [ changeRequest ] ( ) {
123+ async [ create ] ( ) {
124+ this . #created = true ;
125+ this . #busy = true ;
126+
127+ await this [ setup ] ( ) ;
128+
129+ this . dispatchEvent ( creatingEvent ) ;
130+ await this . created ?.( this . #context) ;
131+ this . dispatchEvent ( createdEvent ) ;
132+
133+ this . dispatchEvent ( connectingEvent ) ;
134+ await this . connected ?.( this . #context) ?. catch ( console . error ) ;
135+ this . dispatchEvent ( connectedEvent ) ;
136+
137+ this . #busy = false ;
138+ this . #restart = false ;
139+ await this [ update ] ( ) ;
140+ }
141+
142+ async [ update ] ( ) {
140143
141- if ( this . #changeBusy ) {
142- this . #changeRestart = true ;
143- return this [ changeTask ] ;
144+ if ( this . #busy ) {
145+ this . #restart = true ;
146+ return this [ task ] ;
144147 }
145148
146- this . #changeBusy = true ;
149+ this . #busy = true ;
147150
148- this [ changeTask ] = this [ changeTask ] . then ( async ( ) => {
151+ this [ task ] = this [ task ] . then ( async ( ) => {
149152 // await new Promise((resolve) => {
150153 // window.requestIdleCallback(async () => {
151154
@@ -155,10 +158,10 @@ export default class Component extends HTMLElement {
155158 if ( template ) {
156159 for ( let index = 0 ; index < this . #actions. length ; index ++ ) {
157160
158- if ( this . #changeRestart ) {
161+ if ( this . #restart ) {
159162 await Promise . resolve ( ) . then ( ) . catch ( console . error ) ;
160163 index = - 1 ;
161- this . #changeRestart = false ;
164+ this . #restart = false ;
162165 continue ;
163166 }
164167
@@ -175,7 +178,7 @@ export default class Component extends HTMLElement {
175178 }
176179 }
177180
178- this . #changeBusy = false ;
181+ this . #busy = false ;
179182
180183 await this . rendered ?.( this . #context) ;
181184 this . dispatchEvent ( renderedEvent ) ;
@@ -185,10 +188,10 @@ export default class Component extends HTMLElement {
185188 // });
186189 } ) . catch ( console . error ) ;
187190
188- return this [ changeTask ] ;
191+ return this [ task ] ;
189192 }
190193
191- async # setup ( ) {
194+ async [ setup ] ( ) {
192195
193196 const constructor = this . constructor as typeof Component ;
194197 const observedProperties = constructor . observedProperties ;
@@ -237,13 +240,13 @@ export default class Component extends HTMLElement {
237240 } ,
238241 set ( value ) {
239242 ( this . #context as Record < any , any > ) [ property ] = value ;
240- this [ changeRequest ] ( ) ;
243+ this [ update ] ( ) ;
241244 }
242245 } ) ;
243246
244247 }
245248
246- this . #context = context ( this . #context, this [ changeRequest ] . bind ( this ) ) ;
249+ this . #context = context ( this . #context, this [ update ] . bind ( this ) ) ;
247250
248251 // this.dispatchEvent(renderingEvent);
249252
@@ -273,9 +276,9 @@ export default class Component extends HTMLElement {
273276 // await this.rendered?.(this.#context);
274277 // this.dispatchEvent(renderedEvent);
275278
276- // this.#changeRestart = false;
277- // this.#changeBusy = false;
278- // await this[ changeRequest ]();
279+ // this.#restart = false;
280+ // this.#busy = false;
281+ // await this[ update ]();
279282
280283 // this.dispatchEvent(creatingEvent);
281284 // await this.created?.(this.#context);
0 commit comments