@@ -11,42 +11,51 @@ type ReplicatedModelJS = org.modelix.model.client2.ReplicatedModelJS;
1111type ChangeJS = org . modelix . model . client2 . ChangeJS ;
1212
1313/**
14- * Creates a reactive root node from a client for a given repository and branch.
14+ * Creates a replicated model for a given repository and branch.
15+ * A replicated model exposes a branch that can be used to read and write model data.
16+ * The written model data is automatically synced to the model server.
17+ * Changed from the model server are automatically synced to the branch in the replicated model
1518 *
16- * The returned root node uses Vues reactivity and can be used in Vue like an reactive object.
17- * Changes to the returned node or its descendants are synced to the branch on the model server .
19+ * Also creates root node that uses Vues reactivity and can be used in Vue like a reactive object.
20+ * Changes to model data trigger recalculation of computed properties or re-rendering of components using that data .
1821 *
19- * Calling the returned dispose function stops syncing the root node to the underlying branch on the serever .
22+ * Calling the returned dispose function stops syncing the root node to the underlying branch on the server .
2023 *
2124 * @experimental This feature is expected to be finalized with https://issues.modelix.org/issue/MODELIX-500.
2225 *
2326 * @param client - Reactive reference of a client to a model server.
2427 * @param repositoryId - Reactive reference of a repositoryId on the model server.
2528 * @param branchId - Reactive reference of a branchId in the repository of the model server.
2629 *
27- * @returns {Object } values Wrapper around diffrent returned values.
28- * @returns {Ref<INodeJS | null> } values.rootNode Reactive reference to a reactive root node.
30+ * @returns {Object } values Wrapper around different returned values.
31+ * @returns {Ref<ReplicatedModelJS | null> } values.rootNode Reactive reference to the replicated model for the specified branch.
32+ * @returns {Ref<INodeJS | null> } values.rootNode Reactive reference to the root node with Vue.js reactivity for the specified branch.
2933 * @returns {() => void } values.dispose A function to manually dispose the root node.
3034 * @returns {Ref<unknown> } values.error Reactive reference to a connection error.
3135 */
32- export function useRootNode (
36+ export function useReplicatedModel (
3337 client : MaybeRefOrGetter < ClientJS | null > ,
3438 repositoryId : MaybeRefOrGetter < string | null > ,
3539 branchId : MaybeRefOrGetter < string | null > ,
3640) : {
41+ replicatedModel : Ref < ReplicatedModelJS | null > ;
3742 rootNode : Ref < INodeJS | null > ;
3843 dispose : ( ) => void ;
3944 error : Ref < unknown > ;
4045} {
46+ // Use `replicatedModel` to access the replicated model without tracking overhead of Vue.js.
4147 let replicatedModel : ReplicatedModelJS | null = null ;
48+ const replicatedModelRef : Ref < ReplicatedModelJS | null > = shallowRef ( null ) ;
4249 const rootNodeRef : Ref < INodeJS | null > = shallowRef ( null ) ;
4350 const errorRef : Ref < unknown > = shallowRef ( null ) ;
4451
4552 const dispose = ( ) => {
53+ // Using `replicatedModelRef.value` here would create a circular dependency.
54+ // `toRaw` does not work on `Ref<>`.
4655 if ( replicatedModel !== null ) {
4756 replicatedModel . dispose ( ) ;
4857 }
49- replicatedModel = null ;
58+ replicatedModelRef . value = null ;
5059 rootNodeRef . value = null ;
5160 errorRef . value = null ;
5261 } ;
@@ -86,6 +95,7 @@ export function useRootNode(
8695 } ) ;
8796 const unreactiveRootNode = branch . rootNode ;
8897 const reactiveRootNode = toReactiveINodeJS ( unreactiveRootNode , cache ) ;
98+ replicatedModelRef . value = replicatedModel ;
8999 rootNodeRef . value = reactiveRootNode ;
90100 } else {
91101 connectedReplicatedModel . dispose ( ) ;
@@ -99,6 +109,7 @@ export function useRootNode(
99109 ) ;
100110
101111 return {
112+ replicatedModel : replicatedModelRef ,
102113 rootNode : rootNodeRef ,
103114 dispose,
104115 error : errorRef ,
0 commit comments