createRegistry() RegistryResult RegistryResult.define() customElements.define() ElementResult.register() ElementResult.define() ElementResult
import { MyElement } from './my-element';
import { createRegistry, customElement, html } from 'thunderous';
const registry = createRegistry();
// You could define the element directly like so:
registry.define('my-element', MyElement);
// ...or you could defer the definition until later:
MyElement.register(registry).define('my-element');
RegistryResult.getTagName()
import { createRegistry, customElement, html } from 'thunderous';
import { MyElement } from './my-element';
import { registry } from './registry';
const MyOtherElement = customElement(({ connectedCallback }) => {
connectedCallback(() => {
// get the defined tag name of the custom element
const tagName = registry.getTagName(MyElement);
console.log(tagName); // MY-ELEMENT
});
return html`<div>My Other Element</div>`;
});
// this may be defined in the consumer's project
MyElement.define('my-element');
RegistryResult.getAllTagNames() RegistryResult.eject() CustomElementRegistry customElements RegistryResult.scopedScoped registries are not yet supported in all browsers. To use this feature today, you must install the
<script src="https://unpkg.com/@webcomponents/scoped-custom-element-registry@0.0.10/scoped-custom-element-registry.min.js"></script>
scoped: true createRegistry()
import { ScopedElement } from './scoped-element';
import { createRegistry, customElement, html } from 'thunderous';
// create a scoped custom element registry
const registry = createRegistry({ scoped: true });
console.log(registry.scoped); // true
// define a custom element in the registry
registry.define('scoped-element', ScopedElement);
// use the element in another element's shadow root
const ParentElement = customElement(() => {
return html`<scoped-element></scoped-element>`;
}, {
// pass the registry to the shadow root options
shadowRootOptions: { registry },
});