Skip to content

Commit 2bd6b57

Browse files
author
Pasquale Latrofa
committed
Review:
- Fix typos - Add more examples
1 parent 5f08d63 commit 2bd6b57

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

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

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This how-to provides guidance on using the Model Access API:
1818
The Model Access API allow access to the Mendix model.
1919

2020
The model is split in several components exposed via `studioPro.app.model` object. Currently supported components are:
21-
* BuildinBlocks
21+
* BuildingBlocks
2222
* DomainModels
2323
* Enumerations
2424
* Pages
@@ -32,52 +32,62 @@ const { pages, domainModels } = studioPro.app.model;
3232

3333
An element is part of a Mendix model and all elements together form the logic of the model. Elements may contain other elements. An element always has a container element, which is its parent. The root of an element tree is always a unit.
3434

35-
Each component exposes the units info of the units it is responsible for. The full unit content can be accessed only after loading the unit.
35+
Each component (e.g. `studioPro.app.model.pages` and `studioPro.app.model.domainModels`) exposes the units info of the units it is responsible for. The full unit content can be accessed only after loading the unit.
3636

37-
The unit info contains the the following fields:
38-
| Name | Description |
39-
| --- | --- |
40-
| `$ID` | The unique id of the unit |
41-
| `$Type` | The type of the unit |
42-
| `moduleName` | (Optional) The name of the module containing the unit |
43-
| `name` | (Optional) The name of the unit |
37+
The unit info, described by the `UnitInfo` interface, contains the the following fields:
38+
| Name | Description | Example value |
39+
| --- | --- | --- |
40+
| `$ID` | The unique id of the unit | `077d1338-a548-49a9-baee-c291e93d19af` |
41+
| `$Type` | The type of the unit | `Pages$Page` |
42+
| `moduleName` | (Optional) The name of the module containing the unit | `MyFirstModule` |
43+
| `name` | (Optional) The name of the unit | `ExamplePage` |
4444

4545
All the units managed by the DomainModels component can be retrieved by:
4646

4747
```ts
48-
const unitsInfo = await domainModels.getUnitsInfo()
48+
const unitsInfo: Primitives.UnitInfo[] = await domainModels.getUnitsInfo()
4949
```
5050

51-
Units can be loaded by suppling a function to `loadAll` to execute for each unit. It should return a truthy value to load the unit.
51+
Units can be loaded by supplying a function to `component.loadAll(fn)` to execute for each unit. The function `fn` should return a truthy value to load the specified unit.
5252

5353
The followind snippet loads the DomainModel for the module named `MyFirstModule`:
5454

5555
{{% alert color="warning" %}}
56-
Loading units is an expensive process. Only load the minimun number of units you need when you need them.
56+
Loading units is a resource intensive process. Only load the minimum number of units you need when you need them.
5757
{{% /alert %}}
5858

5959
```ts
60-
const [domainModel] = await domainModels.loadAll((info) => info.moduleName === 'MyFirstModule');
60+
const [domainModel] = await domainModels.loadAll((info: Primitives.UnitInfo) => info.moduleName === 'MyFirstModule');
6161
```
62+
The followind snippet loads the Page named `Home_Web` inside the module named `MyFirstModule`:
6263

64+
```ts
65+
const [page] = await pages.loadAll((info: Primitives.UnitInfo) => info.moduleName === 'MyFirstModule' && info.name === 'Home_Web')
66+
```
6367
## Reading the unit content {#read}
6468

65-
Elements contained inside units can be accessed using the `get<ElementName>` helper methods:
69+
Elements contained inside units can be accessed using the `get<ElementName>` helper methods.
6670

6771
The following snippet will get the Entity named `MyEntity` from the previously loaded DomainModel unit:
6872

6973
```ts
70-
const entity = domainModel.getEntity("MyEntity");
74+
const entity: DomainModels.Entity = domainModel.getEntity("MyEntity");
7175
```
7276

7377
## Modifying the unit content {#modify}
7478

75-
The Mendix model can be modified by leveraing the `add<ElementName>` helper methods:
79+
The Mendix model can be modified by leveraging the `add<ElementName>` helper methods.
7680

7781
The following snippet will create a new Entity inside the previously loaded DomainModel unit:
7882

83+
{{% alert color="warning" %}}
84+
Do not forget to invoke the `component.save(unit)` method after making changes to your unit. The method must be invoked for each modified unit, so changes on multiple units need to be saved separetely.
85+
{{% /alert %}}
86+
7987
```ts
80-
const newEntity = await domainModel.addEntity({ name: "NewEntity", attributes: [{ name: "MyAttribute", type: "AutoNumber" }]})
88+
const newEntity: DomainModels.Entity = await domainModel.addEntity({ name: "NewEntity", attributes: [{ name: "MyAttribute", type: "AutoNumber" }]});
89+
90+
newEntity.documentation = "New documentation";
8191

8292
await domainModels.save(domainModel);
8393
```

0 commit comments

Comments
 (0)