@@ -19,39 +19,38 @@ function isDefined<T>(value: T | null | undefined): value is T {
1919}
2020
2121/**
22- * Creates a replicated model for a given repository and branch .
22+ * Creates replicated models for the given repositories and branches .
2323 * A replicated model exposes a branch that can be used to read and write model data.
2424 * The written model data is automatically synced to the model server.
25- * Changed from the model server are automatically synced to the branch in the replicated model
25+ * Changes from the model server are automatically synced to the branch in the replicated model.
2626 *
27- * Also creates root node that uses Vues reactivity and can be used in Vue like a reactive object .
27+ * Also creates root nodes that use Vue's reactivity and can be used in Vue like reactive objects .
2828 * Changes to model data trigger recalculation of computed properties or re-rendering of components using that data.
2929 *
30- * Calling the returned dispose function stops syncing the root node to the underlying branch on the server.
30+ * Calling the returned dispose function stops syncing the root nodes to the underlying branches on the server.
3131 *
3232 * @param client - Reactive reference of a client to a model server.
33- * @param repositoryId - Reactive reference of a repositoryId on the model server.
34- * @param branchId - Reactive reference of a branchId in the repository of the model server.
33+ * @param models - Reactive reference to an array of ReplicatedModelParameters.
3534 *
3635 * @returns {Object } values Wrapper around different returned values.
37- * @returns {Ref<ReplicatedModelJS | null> } values.rootNode Reactive reference to the replicated model for the specified branch .
38- * @returns {Ref<INodeJS | null > } values.rootNode Reactive reference to the root node with Vue.js reactivity for the specified branch .
39- * @returns {() => void } values.dispose A function to manually dispose the root node .
36+ * @returns {Ref<ReplicatedModelJS | null> } values.replicatedModel Reactive reference to the replicated model for the specified branches .
37+ * @returns {Ref<INodeJS[] > } values.rootNodes Reactive reference to an array of root nodes with Vue.js reactivity for the specified branches .
38+ * @returns {() => void } values.dispose A function to manually dispose the root nodes .
4039 * @returns {Ref<unknown> } values.error Reactive reference to a connection error.
4140 */
4241export function useReplicatedModels (
4342 client : MaybeRefOrGetter < ClientJS | null | undefined > ,
4443 models : MaybeRefOrGetter < ReplicatedModelParameters [ ] | null | undefined > ,
4544) : {
4645 replicatedModel : Ref < ReplicatedModelJS | null > ;
47- rootNode : Ref < INodeJS | null > ;
46+ rootNodes : Ref < INodeJS [ ] > ;
4847 dispose : ( ) => void ;
4948 error : Ref < unknown > ;
5049} {
5150 // Use `replicatedModel` to access the replicated model without tracking overhead of Vue.js.
5251 let replicatedModel : ReplicatedModelJS | null = null ;
5352 const replicatedModelRef : Ref < ReplicatedModelJS | null > = shallowRef ( null ) ;
54- const rootNodeRef : Ref < INodeJS | null > = shallowRef ( null ) ;
53+ const rootNodesRef : Ref < INodeJS [ ] > = shallowRef ( [ ] ) ;
5554 const errorRef : Ref < unknown > = shallowRef ( null ) ;
5655
5756 const dispose = ( ) => {
@@ -61,7 +60,7 @@ export function useReplicatedModels(
6160 replicatedModel . dispose ( ) ;
6261 }
6362 replicatedModelRef . value = null ;
64- rootNodeRef . value = null ;
63+ rootNodesRef . value = [ ] ;
6564 errorRef . value = null ;
6665 } ;
6766
@@ -97,10 +96,12 @@ export function useReplicatedModels(
9796 }
9897 handleChange ( change , cache ) ;
9998 } ) ;
100- const unreactiveRootNode = branch . rootNode ;
101- const reactiveRootNode = toReactiveINodeJS ( unreactiveRootNode , cache ) ;
99+ const unreactiveRootNodes = branch . getRootNodes ( ) ;
100+ const reactiveRootNodes = unreactiveRootNodes . map ( ( node ) =>
101+ toReactiveINodeJS ( node , cache ) ,
102+ ) ;
102103 replicatedModelRef . value = replicatedModel ;
103- rootNodeRef . value = reactiveRootNode ;
104+ rootNodesRef . value = reactiveRootNodes ;
104105 } else {
105106 connectedReplicatedModel . dispose ( ) ;
106107 }
@@ -114,7 +115,7 @@ export function useReplicatedModels(
114115
115116 return {
116117 replicatedModel : replicatedModelRef ,
117- rootNode : rootNodeRef ,
118+ rootNodes : rootNodesRef ,
118119 dispose,
119120 error : errorRef ,
120121 } ;
@@ -172,5 +173,15 @@ export function useReplicatedModel(
172173 ] ;
173174 } ) ;
174175
175- return useReplicatedModels ( client , models ) ;
176+ const result = useReplicatedModels ( client , models ) ;
177+
178+ // Extract the single root node from the array for backward compatibility
179+ const rootNode = computed ( ( ) => result . rootNodes . value [ 0 ] ?? null ) ;
180+
181+ return {
182+ replicatedModel : result . replicatedModel ,
183+ rootNode : rootNode ,
184+ dispose : result . dispose ,
185+ error : result . error ,
186+ } ;
176187}
0 commit comments