1- import  {   defValue   }  from  "@default-js/defaultjs-common-utils/src/ObjectUtils " ; 
1+ import  { privateProperty   }  from  "@default-js/defaultjs-common-utils/src/PrivateProperty " ; 
22import  {  lazyPromise  }  from  "@default-js/defaultjs-common-utils/src/PromiseUtils" ; 
33import  {  uuid  }  from  "@default-js/defaultjs-common-utils/src/UUID" ; 
44import  {  initTimeout ,  triggerTimeout  }  from  "./Constants" ; 
55import  {  attributeChangeEventname ,  componentEventname  }  from  "./utils/EventHelper" ; 
66import  WeakData  from  "./utils/WeakData" ; 
77
8+ const  PRIVATE_READY  =  "ready" ; 
9+ 
810const  TIMEOUTS  =  new  WeakData ( ) ; 
911const  init  =  ( component )  =>  { 
1012	const  data  =  TIMEOUTS . data ( component ) ; 
@@ -37,7 +39,7 @@ export const createUID = (prefix, suffix) => {
3739class  Component  extends  HTMLElement  { 
3840	constructor ( { shadowRoot =  false ,  content =  null ,  createUID =  false ,  uidPrefix =  "id-" ,  uidSuffix =  "" }  =  { } )  { 
3941		super ( ) ; 
40- 		defValue ( this ,  "ready" ,  lazyPromise ( ) ) ; 
42+ 		privateProperty ( this ,  PRIVATE_READY ,  lazyPromise ( ) ) ; 
4143
4244		if ( createUID ) 
4345			this . attr ( "id" ,  createUID ( uidPrefix ,  uidSuffix ) ) ; 
@@ -53,8 +55,17 @@ class Component extends HTMLElement {
5355		return  this . shadowRoot  ||  this ; 
5456	} 
5557
58+ 	get  ready ( ) { 
59+ 		return  privateProperty ( this ,  PRIVATE_READY ) ; 
60+ 	} 
61+ 
5662	async  init ( )  { } 
5763
64+ 	async  destroy ( )  { 
65+ 		if ( this . ready . resolved ) 
66+ 			privateProperty ( this ,  PRIVATE_READY ,  lazyPromise ( ) ) ; 
67+ 	} 
68+ 
5869	connectedCallback ( )  { 
5970		if  ( this . ownerDocument  ==  document )  init ( this ) ; 
6071	} 
@@ -69,6 +80,10 @@ class Component extends HTMLElement {
6980			this . trigger ( triggerTimeout ,  componentEventname ( "change" ,  this ) ) ; 
7081		} 
7182	} 
83+ 
84+ 	disconnectedCallback ( ) { 
85+ 		this . destroy ( ) ; 
86+ 	} 
7287} 
7388
7489export  default  Component ; 
0 commit comments