Skip to content

Commit 43355c0

Browse files
committed
docs: explain role of ReplicatedModel in client v2 docs
1 parent 931ffc0 commit 43355c0

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

docs/global/modules/core/pages/howto/usage-model-client-v2.adoc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,30 @@ runBlocking(CoroutineScope(Dispatchers.Default).coroutineContext){
4949

5050
--
5151

52-
Afterward, we create a repository and replicate it locally (we assume coroutine execution):
52+
Afterward, we create a repository and replicate it locally into a `ReplicatedModel`.
53+
This data structure automatically synchronizes its content with the remote.
54+
We can consequently assume that its data is always correct and up-to-date.
55+
To ensure this, we need to use read and write transactions whenever we interact with the content, e.g. by adding a new child (we assume coroutine execution):
5356

5457
[source, kotlin]
5558
--
56-
5759
var rootNode: INode? = null
5860
// we need to start a read transaction to obtain model content
5961
replicatedModel.getBranch().getArea().executeRead {
6062
// initial root node after repository initialization has the id 1
6163
rootNode = replicatedModel.getBranch().getRootNode()
6264
}
6365

64-
// we need to exit the read transaction before we start a write transaction
66+
// we need to exit the read before we write
6567
replicatedModel.getBranch().getArea().executeWrite {
66-
val addNewChild: INode? = rootNode?.addNewChild("myRole")
67-
println("Added node $addNewChild under parent ${addNewChild?.parent}")
68+
val newChild: INode? = rootNode?.addNewChild("myRole")
69+
println("Added node $newChild under parent ${newChild?.parent}")
6870
}
6971

70-
// to get data from the replicated model, we need to start a read transaction
72+
// we need to start a read transaction again to get model content
7173
replicatedModel.getBranch().getArea().executeRead {
72-
println("All nodes: ${rootNode?.getDescendants(true)?.map { (it as PNodeAdapter).nodeId }}")
74+
println("All nodes in repository: ${(rootNode?.getDescendants(true)?.toMutableList().map { (it as PNodeAdapter).nodeId.toString() })}")
7375
}
74-
7576
--
7677

7778
CAUTION: If you try to access a node that does not exist, an exception is thrown.

0 commit comments

Comments
 (0)