Skip to content

Commit 8f1b379

Browse files
Hankshajefftoffoli
authored andcommitted
Optimize command registration by caching enabled and toggled states (eclipse-theia#16325)
Signed-off-by: Vivien Jovet <[email protected]>
1 parent c4e8b94 commit 8f1b379

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/core/src/browser/menu/browser-menu-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,12 @@ export class DynamicMenuWidget extends MenuWidget {
342342

343343
} else if (CommandMenu.is(node)) {
344344
const id = !phCommandRegistry.hasCommand(node.id) ? node.id : `${node.id}:${DynamicMenuWidget.nextCommmandId++}`;
345+
const enabled = node.isEnabled(nodePath, ...(this.args || []));
346+
const toggled = node.isToggled ? !!node.isToggled(nodePath, ...(this.args || [])) : false;
345347
phCommandRegistry.addCommand(id, {
346348
execute: () => { node.run(nodePath, ...(this.args || [])); },
347-
isEnabled: () => node.isEnabled(nodePath, ...(this.args || [])),
348-
isToggled: () => node.isToggled ? !!node.isToggled(nodePath, ...(this.args || [])) : false,
349+
isEnabled: () => enabled,
350+
isToggled: () => toggled,
349351
isVisible: () => true,
350352
label: node.label,
351353
iconClass: node.icon,

0 commit comments

Comments
 (0)