Last active
March 6, 2018 21:14
-
-
Save bgrins/0b139d1af466f560c8917005c911475b to your computer and use it in GitHub Desktop.
Lazy Custom Element registrations
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
<script src="app.js"></script> | |
<element-1 /> | |
<element-2 /> |
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
// Option 1 - Module path: | |
// Pass a module path and an export name which will lazily get imported | |
// when that tag name is enountered. | |
customElements.define('element-1', './element1', 'Element1'); | |
customElements.define('element-module', './element-module.html'); | |
// Option 2 - Custom Handler function: | |
// Gets called when a valid custom element name is encountered *and* there | |
// isn't already a registration | |
customElements.definitionHandler((name) => { | |
if (name == "element-2") { | |
import {Element2} from "./element2"; | |
return Element2; | |
} | |
}); |
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
export class Element1 extends HTMLElement { | |
connectedCallback() { | |
} | |
} |
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
export class Element2 extends HTMLElement { | |
connectedCallback() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment