Skip to content

Commit

Permalink
bug/issue 144 check CE registry before assuming a custom element defi…
Browse files Browse the repository at this point in the history
…nition exists (#146)

* refactor and use registry check for ecxisting custom elements

* track custom elements registry spec slignment TODO

* fix linting

* refactor and TODO comment for spec alignment

* correct comment
  • Loading branch information
thescientist13 authored Mar 9, 2024
1 parent bead03d commit 13a3b72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/dom-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,20 @@ class HTMLTemplateElement extends HTMLElement {
// https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
class CustomElementsRegistry {
constructor() {
this.customElementsRegistry = {};
// TODO this should probably be a set or otherwise follow the spec?
// https://github.com/ProjectEvergreen/wcc/discussions/145
this.customElementsRegistry = new Map();
}

define(tagName, BaseClass) {
this.customElementsRegistry[tagName] = BaseClass;
// TODO this should probably fail as per the spec...
// e.g. if(this.customElementsRegistry.get(tagName))
// https://github.com/ProjectEvergreen/wcc/discussions/145
this.customElementsRegistry.set(tagName, BaseClass);
}

get(tagName) {
return this.customElementsRegistry[tagName];
return this.customElementsRegistry.get(tagName);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti

// https://github.com/ProjectEvergreen/wcc/pull/67/files#r902061804
const { pathname } = elementURL;
const element = tagName
? customElements.get(tagName)
: (await import(pathname)).default;
const element = customElements.get(tagName) ?? (await import(pathname)).default;
const dataLoader = (await import(pathname)).getData;
const data = props
? props
Expand Down

0 comments on commit 13a3b72

Please sign in to comment.