From 31ac65eb185eaebef7028fe5a1d09b2963b905d5 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 14 Aug 2019 19:55:47 -0700 Subject: [PATCH] Use a Set for checking if a value exists in a collection --- modern/src/Actions.ts | 9 ++++----- modern/src/App.js | 5 ++++- modern/src/runtime/Layout.js | 2 +- modern/src/utils.js | 12 ++---------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/modern/src/Actions.ts b/modern/src/Actions.ts index 97ef2889..6503851e 100644 --- a/modern/src/Actions.ts +++ b/modern/src/Actions.ts @@ -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, diff --git a/modern/src/App.js b/modern/src/App.js index 72d5e868..f540fd53 100644 --- a/modern/src/App.js +++ b/modern/src/App.js @@ -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); diff --git a/modern/src/runtime/Layout.js b/modern/src/runtime/Layout.js index cbeaf49c..e4b6c707 100644 --- a/modern/src/runtime/Layout.js +++ b/modern/src/runtime/Layout.js @@ -13,7 +13,7 @@ class Layout extends GuiObject { } getcontainer() { - return findParentNodeOfType(this, ["container"]); + return findParentNodeOfType(this, new Set(["container"])); } resize(x, y, w, h) { diff --git a/modern/src/utils.js b/modern/src/utils.js index 65bda88e..33b9f72f 100644 --- a/modern/src/utils.js +++ b/modern/src/utils.js @@ -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);