Use a Set for checking if a value exists in a collection

This commit is contained in:
Jordan Eldredge 2019-08-14 19:55:47 -07:00
parent 1ebfb0ada7
commit 31ac65eb18
4 changed files with 11 additions and 17 deletions

View file

@ -49,11 +49,10 @@ function gotSkinZip(zip: JSZip, store: ModernStore) {
if (node.attributes.file.endsWith("standardframe.maki")) {
break;
}
const scriptGroup = Utils.findParentNodeOfType(node, [
"group",
"WinampAbstractionLayer",
"WasabiXML",
]);
const scriptGroup = Utils.findParentNodeOfType(
node,
new Set(["group", "WinampAbstractionLayer", "WasabiXML"])
);
const system = new System(scriptGroup, store);
run({
runtime,

View file

@ -20,7 +20,10 @@ function handleMouseEventDispatch(node, event, eventName) {
// In order to properly calculate the x/y coordinates like MAKI does we need
// to find the container element and calculate based off of that
const container = Utils.findParentOrCurrentNodeOfType(node, "container");
const container = Utils.findParentOrCurrentNodeOfType(
node,
new Set(["container"])
);
const x = event.clientX - container.getleft();
const y = event.clientY - container.gettop();
node.js_trigger(eventName, x, y);

View file

@ -13,7 +13,7 @@ class Layout extends GuiObject {
}
getcontainer() {
return findParentNodeOfType(this, ["container"]);
return findParentNodeOfType(this, new Set(["container"]));
}
resize(x, y, w, h) {

View file

@ -101,26 +101,18 @@ export function unimplementedWarning(name) {
}
// Operations on trees
function isNodeOfType(node, type) {
const isTypeArray = Array.isArray(type);
return (
(!isTypeArray && node.name === type) ||
(isTypeArray && type.includes(node.name))
);
}
export function findParentNodeOfType(node, type) {
let n = node;
while (n.parent) {
n = n.parent;
if (isNodeOfType(n, type)) {
if (type.has(n.name)) {
return n;
}
}
}
export function findParentOrCurrentNodeOfType(node, type) {
if (isNodeOfType(node, type)) {
if (type.has(node.name)) {
return node;
} else {
return findParentNodeOfType(node, type);