Skip to content

Commit 925b3b1

Browse files
committed
Some documentation for the light model client
1 parent 1f174a9 commit 925b3b1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

light-model-client/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Light Model Client
2+
3+
This client is designed to connect to MPS or the Modelix model server.
4+
It is implemented in Kotlin multi-platform so that it can run in the browser.
5+
6+
While the "advanced model client" provides more features and should be used for long-running processes,
7+
the "light model client" is optimized for a lower resource consumption and short living processes like in a browser tab.
8+
The server is responsible for resolving conflicts and to keep the client side model in a valid state.
9+
10+
Creating an instance that loads the entire model from the server can be done like this:
11+
12+
```
13+
val client = LightModelClientJVM.builder()
14+
.url("ws://localhost/json/v2/test-repo/ws") // optional, by default it connects to the MPS plugin
15+
.build()
16+
client.changeQuery(buildModelQuery {
17+
root {
18+
descendants { }
19+
}
20+
})
21+
val rootNode = client.waitForRootNode()!!
22+
client.runRead {
23+
val modules = rootNode.getChildren("modules")
24+
// ...
25+
}
26+
```
27+
28+
You have to set a *model query* using `changeQuery()` to tell the server in what data you are interested in.
29+
Without a query the client will not receive any data.
30+
If you try to access a node that is not included in you *model query* an exception is thrown.
31+
You can use `INode.isLoaded()` to check is a node was loaded on the client to prevent this exception.
32+
You can also filter a list of nodes like this: `node.getChildren("modules").filterLoaded()`,
33+
to iterate only over the nodes that are included in your query.
34+
35+
To read/write any nodes you have to start a read/write transaction by using `runRead {}`/`runWrite {}`.
36+
An exception is thrown when you try to access a node outside a transaction.

0 commit comments

Comments
 (0)