From 38428b0fc5b96918f282d4e528ae3b2322d3f73d Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 30 Aug 2024 17:09:15 +0100 Subject: [PATCH] refactor: Use arrow functions when calling Array.prototype.filter --- core/events/utils.ts | 9 ++------- core/utils/toolbox.ts | 6 +++--- core/workspace.ts | 10 ++-------- core/workspace_svg.ts | 4 +--- tests/mocha/event_test.js | 6 +++--- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/core/events/utils.ts b/core/events/utils.ts index 7a2aca8ada9..4753e7783d9 100644 --- a/core/events/utils.ts +++ b/core/events/utils.ts @@ -127,13 +127,8 @@ function fireNow() { const queue = filter(FIRE_QUEUE, true); FIRE_QUEUE.length = 0; for (const event of queue) { - if (!event.workspaceId) { - continue; - } - const eventWorkspace = common.getWorkspaceById(event.workspaceId); - if (eventWorkspace) { - eventWorkspace.fireChangeListener(event); - } + if (!event.workspaceId) continue; + common.getWorkspaceById(event.workspaceId)?.fireChangeListener(event); } } diff --git a/core/utils/toolbox.ts b/core/utils/toolbox.ts index fbf031ac612..296bb6dcc94 100644 --- a/core/utils/toolbox.ts +++ b/core/utils/toolbox.ts @@ -285,9 +285,9 @@ function hasCategoriesInternal(toolboxJson: ToolboxInfo | null): boolean { return toolboxKind === CATEGORY_TOOLBOX_KIND; } - const categories = toolboxJson['contents'].filter(function (item) { - return item['kind'].toUpperCase() === 'CATEGORY'; - }); + const categories = toolboxJson['contents'].filter( + (item) => item['kind'].toUpperCase() === 'CATEGORY', + ); return !!categories.length; } diff --git a/core/workspace.ts b/core/workspace.ts index bc09d36fb4b..75bcd81470c 100644 --- a/core/workspace.ts +++ b/core/workspace.ts @@ -255,9 +255,7 @@ export class Workspace implements IASTNodeLocation { blocks.sort(this.sortObjects_.bind(this)); } - return blocks.filter(function (block: Block) { - return !block.isInsertionMarker(); - }); + return blocks.filter((block) => !block.isInsertionMarker()); } /** @@ -341,11 +339,7 @@ export class Workspace implements IASTNodeLocation { // Insertion markers exist on the workspace for rendering reasons, but // aren't "real" blocks from a developer perspective. - const filtered = blocks.filter(function (block) { - return !block.isInsertionMarker(); - }); - - return filtered; + return blocks.filter((block) => !block.isInsertionMarker()); } /** Dispose of all blocks and comments in workspace. */ diff --git a/core/workspace_svg.ts b/core/workspace_svg.ts index a01bbe07e87..a7d56d1005e 100644 --- a/core/workspace_svg.ts +++ b/core/workspace_svg.ts @@ -543,9 +543,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // Update all blocks in workspace that have a style name. this.updateBlockStyles_( - this.getAllBlocks(false).filter(function (block) { - return !!block.getStyleName(); - }), + this.getAllBlocks(false).filter((block) => !!block.getStyleName()), ); // Update current toolbox selection. diff --git a/tests/mocha/event_test.js b/tests/mocha/event_test.js index 545659f2d76..2669cc8548c 100644 --- a/tests/mocha/event_test.js +++ b/tests/mocha/event_test.js @@ -1745,9 +1745,9 @@ suite('Events', function () { // Fire all events this.clock.runAll(); - const disabledEvents = this.workspace.getUndoStack().filter(function (e) { - return e.element === 'disabled'; - }); + const disabledEvents = this.workspace + .getUndoStack() + .filter((e) => e.element === 'disabled'); assert.isEmpty( disabledEvents, 'Undo stack should not contain any disabled events',