@@ -22,6 +22,11 @@ export default function registerCustomElement(tag, options = {}) {
2222 typeof options . attributeChangedCallback === 'function' && options . attributeChangedCallback . call ( this , name , oldValue , value ) ;
2323 }
2424
25+ function define ( tagName , CustomElement ) {
26+ const existingCustomElement = customElements . get ( tagName ) ;
27+ return typeof existingCustomElement !== 'undefined' ? existingCustomElement : customElements . define ( tagName , CustomElement ) ;
28+ }
29+
2530 if ( isES2015 ) {
2631 // ES2015 detected. We will use "class" based Custom Elements V1 specification.
2732 // If it's natively supported it will run without polyfill
@@ -45,7 +50,7 @@ export default function registerCustomElement(tag, options = {}) {
4550 CustomElement . prototype . disconnectedCallback = disconnectedCallback ;
4651 CustomElement . prototype . attributeChangedCallback = attributeChangedCallback ;
4752
48- customElements . define ( tag , CustomElement ) ;
53+ define ( tag , CustomElement ) ;
4954 return CustomElement ; // eslint-disable-line consistent-return
5055 } else { // eslint-disable-line no-else-return
5156 // not ES2015. We will use polyfill supported version of registering Custom Elements
@@ -73,7 +78,7 @@ export default function registerCustomElement(tag, options = {}) {
7378 CustomElement . prototype . disconnectedCallback = disconnectedCallback ;
7479 CustomElement . prototype . attributeChangedCallback = attributeChangedCallback ;
7580
76- customElements . define ( tag , CustomElement ) ;
81+ define ( tag , CustomElement ) ;
7782 return CustomElement ; // eslint-disable-line consistent-return
7883 }
7984}
0 commit comments