Jelajahi Sumber

fix: Register models always returns new ref

Owen Diffey 1 tahun lalu
induk
melakukan
b7017725e7
1 mengubah file dengan 7 tambahan dan 2 penghapusan
  1. 7 2
      frontend/src/stores/models/model.ts

+ 7 - 2
frontend/src/stores/models/model.ts

@@ -64,10 +64,15 @@ export const createModelStore = modelName => {
 	const registerModels = async docs =>
 		Promise.all(
 			(Array.isArray(docs) ? docs : [docs]).map(async _doc => {
-				const docRef = ref(_doc);
+				const existingRef = models.value.find(
+					model => model.value._id === _doc._id
+				);
 
-				if (!models.value.find(model => model.value._id === _doc._id))
+				const docRef = existingRef ?? ref(_doc);
+
+				if (!existingRef) {
 					models.value.push(docRef);
+				}
 
 				if (subscriptions.value[_doc._id]) return docRef;