Skip to content

Commit

Permalink
feat(framework): support several runtimes simultaneously (#1691)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev authored Jun 3, 2020
1 parent 095d6dc commit 7a3261c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
30 changes: 26 additions & 4 deletions packages/base/src/CustomElementsRegistry.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
const DefinitionsSet = new Set();
const Definitions = new Set();
const Failures = new Set();
let failureTimeout;

const registerTag = tag => {
DefinitionsSet.add(tag);
Definitions.add(tag);
};

const isTagRegistered = tag => {
return DefinitionsSet.has(tag);
return Definitions.has(tag);
};

const getAllRegisteredTags = () => {
const arr = [];
DefinitionsSet.forEach(tag => {
Definitions.forEach(tag => {
arr.push(tag);
});
return arr;
};

const recordTagRegistrationFailure = tag => {
Failures.add(tag);
if (!failureTimeout) {
failureTimeout = setTimeout(() => {
displayFailedRegistrations();
failureTimeout = undefined;
}, 1000);
}
};

const displayFailedRegistrations = () => {
const tags = []; // IE only supports Set.prototype.forEach
Failures.forEach(tag => {
tags.push(tag);
});
console.warn(`The following tags have already been defined by a different UI5 Web Components version: ${tags.join(", ")}`); // eslint-disable-line
Failures.clear();
};

export {
registerTag,
isTagRegistered,
getAllRegisteredTags,
recordTagRegistrationFailure,
};
4 changes: 2 additions & 2 deletions packages/base/src/UI5Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import boot from "./boot.js";
import UI5ElementMetadata from "./UI5ElementMetadata.js";
import StaticAreaItem from "./StaticAreaItem.js";
import RenderScheduler from "./RenderScheduler.js";
import { registerTag, isTagRegistered } from "./CustomElementsRegistry.js";
import { registerTag, isTagRegistered, recordTagRegistrationFailure } from "./CustomElementsRegistry.js";
import DOMObserver from "./compatibility/DOMObserver.js";
import { skipOriginalEvent } from "./config/NoConflict.js";
import getConstructableStyle from "./theming/getConstructableStyle.js";
Expand Down Expand Up @@ -901,7 +901,7 @@ class UI5Element extends HTMLElement {
const definedGlobally = customElements.get(tag);

if (definedGlobally && !definedLocally) {
console.warn(`Skipping definition of tag ${tag}, because it was already defined by another instance of ui5-webcomponents.`); // eslint-disable-line
recordTagRegistrationFailure(tag);
} else if (!definedGlobally) {
this._generateAccessors();
registerTag(tag);
Expand Down
3 changes: 1 addition & 2 deletions packages/base/src/delegate/ItemNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "../Keys.js";

import EventProvider from "../EventProvider.js";
import UI5Element from "../UI5Element.js";
import NavigationMode from "../types/NavigationMode.js";
import ItemNavigationBehavior from "../types/ItemNavigationBehavior.js";

Expand Down Expand Up @@ -193,7 +192,7 @@ class ItemNavigation extends EventProvider {

const currentItem = items[this.currentIndex];

if (currentItem instanceof UI5Element) {
if (currentItem.isUI5Element) {
return currentItem.getFocusDomRef();
}

Expand Down
5 changes: 2 additions & 3 deletions packages/base/src/delegate/ResizeHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import UI5Element from "../UI5Element.js";
import NativeResize from "./NativeResize.js";
import CustomResize from "./CustomResize.js";

Expand Down Expand Up @@ -38,7 +37,7 @@ class ResizeHandler {
* @memberof ResizeHandler
*/
static register(ref, callback) {
if (ref instanceof UI5Element) {
if (ref.isUI5Element) {
ref = ref.getDomRef();
}

Expand All @@ -53,7 +52,7 @@ class ResizeHandler {
* @memberof ResizeHandler
*/
static deregister(ref, callback) {
if (ref instanceof UI5Element) {
if (ref.isUI5Element) {
ref = ref.getDomRef();
}

Expand Down
3 changes: 1 addition & 2 deletions packages/base/src/util/FocusableElements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import UI5Element from "../UI5Element.js";
import isNodeHidden from "./isNodeHidden.js";
import isNodeClickable from "./isNodeClickable.js";

Expand Down Expand Up @@ -32,7 +31,7 @@ const findFocusableElement = (container, forward) => {
while (child) {
const originalChild = child;

child = child instanceof UI5Element ? child.getFocusDomRef() : child;
child = child.isUI5Element ? child.getFocusDomRef() : child;
if (!child) {
return null;
}
Expand Down

0 comments on commit 7a3261c

Please sign in to comment.