@@ -21,21 +21,21 @@ class <%= elementClassName %> extends PFElement {
2121< % _ } _ % >
2222 }
2323
24- < % _ if ( attributes . length > 0 ) { _ % >
25- static get observedAttributes ( ) {
26- return [ < % if ( isPfelement ) { % > < % - _ . join ( attributes . map ( item => `"pfe-${ item } "` ) , ", " ) % > < % } else { % > < % - _ . join ( attributes . map ( item => `"${ item } "` ) , ", " ) % > < % } % > ] ;
27- }
28- < % _ } else { _ % >
29- // static get observedAttributes() {
30- // return [];
31- // }
32- < % _ } _ % >
24+ < % if ( events . length < 1 ) { % > // <% } %>static get events() {
25+ < % if ( events . length < 1 ) { % > // <% } %>return {<% for(let i = 0; i < events.length; i++) { %>
26+ < %= events [ i ] % > : `${ this . tag } :<%= events[i] %>` < % if ( i < ( events . length - 1 ) ) { % > , < % } } % >
27+ < % if ( events . length < 1 ) { % > // <% } %> };
28+ < % if ( events . length < 1 ) { % > // <% } %> }
3329
3430 // Declare the type of this component
3531 static get PfeType ( ) {
3632 return PFElement . PfeTypes . < %= _ . capitalize ( template_type ) % > ;
3733 }
3834
35+ < % if ( attributes . length < 1 ) { % > / / < % } % > static get observedAttributes ( ) {
36+ < % if ( attributes . length < 1 ) { % > // <% } %>return [<% if (isPfelement) { %><%- _.join(attributes.map(item => `"pfe-${item}"`), ", ") %><% } else { %><%- _.join(attributes.map(item => `"${item}"`), ", ") %><% } %>];
37+ < % if ( attributes . length < 1 ) { % > // <% } %> }
38+
3939 constructor ( ) {
4040 super ( < %= elementClassName % > , { type : < %= elementClassName % > . PfeType } );
4141 < % _ if ( slots . length > 0) { % >
@@ -56,17 +56,31 @@ class <%= elementClassName %> extends PFElement {
5656 // this.< %= slots [ i ] % > .addEventListener("slotchange", this._init);
5757 < % _ } _ % >
5858 < % _ } _ % >
59+
60+ < % _ for ( let i = 0 ; i < events . length ; i ++ ) { _ % >
61+ this.addEventListener(< %= elementClassName % > .events.< %= events [ i ] % > , this._< %= events [ i ] % > Handler);
62+ < % _ } _ % >
5963 }
6064
61- // disconnectedCallback() {}
65+ disconnectedCallback ( ) {
66+ < % _ for ( let i = 0 ; i < events . length ; i ++ ) { _ % >
67+ this . removeEventListener ( < %= elementClassName % > .events.< %= events [ i ] % > , this . _ < %= events [ i ] % > Handler ) ;
68+ < % _ } _%>
69+ }
6270
6371< % _ if ( attributes . length > 0) { _ % >
6472 // Process the attribute change
65- attributeChangedCallback ( attr , oldValue , newValue ) {
66- super . attributeChangedCallback ( attr , oldValue , newValue ) ;
73+ < % if ( attributes . length < 1 ) { % > // <% } %>attributeChangedCallback(attr, oldValue, newValue) {
74+ < % if ( attributes . length < 1 ) { % > // <% } %>super.attributeChangedCallback(attr, oldValue, newValue);
75+ < % if ( attributes . length < 1 ) { % > // <% } %> }
76+ < % _ } _%>
77+
78+ < % _ for ( let i = 0 ; i < events . length ; i ++ ) { _ % >
79+ _< %= events [ i ] % > Handler(event) {
80+ this . emitEvent ( < %= elementClassName % > .events.< %= events [ i ] % > , {
81+ detail : { }
82+ } ) ;
6783 }
68- < % _ } else { _ % >
69- // attributeChangedCallback(attr, oldValue, newValue) { }
7084< % _ } _ % >
7185}
7286
0 commit comments