Skip to content

Commit 37e86bb

Browse files
committed
Fix broken command api code sample
1 parent 3fe4be2 commit 37e86bb

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

  • content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/command-api.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,25 @@ The `registerCommand` requires a generic type for the command payload once execu
3030
For commands that require payload, you must make sure you register the command with the exact expected payload object type. See the [App Explorer API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/app-explorer-api/) and [Documents API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/documents-api/) documentation for clear examples.
3131

3232
```typescript
33-
import { ComponentContext, IComponent, Menu, StudioProApi, getStudioProApi } from "@mendix/extensions-api";
34-
33+
import { ComponentContext, IComponent, StudioProApi, getStudioProApi } from "@mendix/extensions-api";
3534
const extensionId = "myextension";
3635

3736
export const component: IComponent = {
3837
async loaded(componentContext: ComponentContext) {
3938
const studioPro = getStudioProApi(componentContext);
4039

41-
await this.createMenuWithCommand(studioPro);
42-
}
43-
44-
async createMenuWithCommand(studioPro: StudioProApi) {
45-
const commandId = `${extensionId}.menu-command`;
46-
const menuId = `${commandId}.menu`;
47-
48-
await studioPro.app.commands.registerCommand<void>(
49-
commandId,
50-
async () => await studioPro.ui.messageBoxes.show("info", `This menu executed a command with id '${commandId}'`)
51-
);
52-
53-
await studioPro.ui.extensionsMenu.add({ caption: "Menu with command", menuId, commandId });
40+
await createMenuWithCommand(studioPro);
5441
}
42+
};
43+
async function createMenuWithCommand(studioPro: StudioProApi) {
44+
const commandId = `${extensionId}.menu-command`;
45+
const menuId = `${commandId}.menu`;
46+
47+
await studioPro.app.commands.registerCommand(
48+
commandId,
49+
async () => await studioPro.ui.messageBoxes.show("info", `This menu executed a command with id '${commandId}'`)
50+
);
51+
await studioPro.ui.extensionsMenu.add({ caption: "Menu with command", menuId, commandId });
5552
}
5653
```
5754

0 commit comments

Comments
 (0)