-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't define dependencies in the constructor. add version variab…
…le for better comparison chore: adjust eslint config to match the v8 specs:
- Loading branch information
Showing
5 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,8 @@ | |
"no-console": "off" | ||
} | ||
} | ||
] | ||
], | ||
"globals": { | ||
"__LEU_VERSION__": "readonly" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
import { LitElement } from "lit" | ||
|
||
export class LeuElement extends LitElement { | ||
static version = __LEU_VERSION__ | ||
|
||
static dependencies = {} | ||
|
||
static define(name, constructor = this, options = {}) { | ||
if (!customElements.get(name)) { | ||
Object.entries(this.dependencies).forEach(([n, c]) => c.define(n)) | ||
|
||
const currentlyRegisteredConstructor = customElements.get(name) | ||
|
||
if (currentlyRegisteredConstructor === undefined) { | ||
customElements.define(name, constructor, options) | ||
} else { | ||
console.info(`${name} is already defined`) | ||
return | ||
} | ||
} | ||
|
||
constructor() { | ||
super() | ||
if (currentlyRegisteredConstructor !== constructor) { | ||
console.warn( | ||
`The custom element with the name <${name}> is already registered with a different constructor. This can happen when the same element has been loaded from different modules (e.g. multiple CDN requests or bundles).` | ||
) | ||
return | ||
} | ||
|
||
Object.entries(this.constructor.dependencies).forEach( | ||
([name, component]) => { | ||
this.constructor.define(name, component) | ||
} | ||
) | ||
if (currentlyRegisteredConstructor.version !== constructor.version) { | ||
console.warn( | ||
`The custom element with the name <${name}> is already defined with the same constructor but a different version (${currentlyRegisteredConstructor.version}).` | ||
) | ||
} | ||
} | ||
} |