Skip to content
Snippets Groups Projects
Commit f1cbab27 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Allow calling defineCustomElement multiple times with the same element

In case we try to register the element multiple times under the same name
just do nothing. This allows us to not register things by default and
register under the same name in multiple places where needed without
coordination.
parent a0b74ff2
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,15 @@ suite('utils', () => {
expect(node.foo).to.equal(42);
});
test('defineCustomElement multiple times', () => {
class SomeElement2 extends HTMLElement {
}
let res = utils.defineCustomElement("test-some-element-2", SomeElement2);
assert.isTrue(res);
res = utils.defineCustomElement("test-some-element-2", SomeElement2);
assert.isTrue(res);
});
test('getAPiUrl', () => {
assert(utils.getAPiUrl().startsWith("http"));
});
......
......@@ -103,6 +103,10 @@ export const base64EncodeUnicode = (str) => {
* @param {object} options
*/
export const defineCustomElement = (name, constructor, options) => {
// In case the constructor is already defined just do nothing
if (customElements.get(name) === constructor) {
return true;
}
// Checks taken from https://github.com/webcomponents/webcomponentsjs/blob/master/webcomponents-loader.js
if (!('attachShadow' in Element.prototype && 'getRootNode' in Element.prototype && window.customElements)) {
var elements = document.getElementsByTagName(name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment