Skip to content

Commit 9a963a0

Browse files
committed
Re implment the CustomElementRegistry interface
1 parent 10f8e07 commit 9a963a0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/custom-elements/ts_src/CustomElementRegistry.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ export default class CustomElementRegistry {
278278
return undefined;
279279
}
280280

281+
getName(constructor: ElementConstructor): string | null {
282+
const definition = this._constructorToDefinition.get(constructor);
283+
return definition ? definition.localName : null;
284+
}
285+
281286
whenDefined(localName: string): Promise<void> {
282287
if (!Utilities.isValidCustomElementName(localName)) {
283288
return Promise.reject(
@@ -363,4 +368,6 @@ CustomElementRegistry.prototype['polyfillDefineLazy'] =
363368
CustomElementRegistry.prototype.polyfillDefineLazy;
364369
CustomElementRegistry.prototype['polyfillWrapFlushCallback'] =
365370
CustomElementRegistry.prototype.polyfillWrapFlushCallback;
371+
CustomElementRegistry.prototype['getName'] =
372+
CustomElementRegistry.prototype.getName;
366373
/* eslint-enable no-self-assign */

packages/tests/custom-elements/html/registry.test.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@
209209
});
210210
});
211211

212+
suite('getName', function () {
213+
test('returns the local name for a defined custom element constructor', function () {
214+
class XGetName extends HTMLElement {}
215+
customElements.define('x-get-name', XGetName);
216+
217+
var name = customElements.getName(XGetName);
218+
assert.equal(name, 'x-get-name');
219+
});
220+
221+
test('returns null for an undefined custom element constructor', function () {
222+
class XUndefinedElement extends HTMLElement {}
223+
224+
var name = customElements.getName(XUndefinedElement);
225+
assert.isNull(name);
226+
});
227+
});
228+
212229
suite('whenDefined', function () {
213230
test('resolves when a tag is defined', function () {
214231
var promise = customElements

0 commit comments

Comments
 (0)