mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-21 09:09:01 +00:00
Use a Set for checking if a value exists in a collection
This commit is contained in:
parent
1ebfb0ada7
commit
31ac65eb18
4 changed files with 11 additions and 17 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Layout extends GuiObject {
|
|||
}
|
||||
|
||||
getcontainer() {
|
||||
return findParentNodeOfType(this, ["container"]);
|
||||
return findParentNodeOfType(this, new Set(["container"]));
|
||||
}
|
||||
|
||||
resize(x, y, w, h) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue