Skip to content

Commit 30a8ab9

Browse files
committed
Fix the watch source warning
1 parent 629cd27 commit 30a8ab9

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grapoza/vue-tree",
3-
"version": "6.1.0",
3+
"version": "6.1.1",
44
"description": "Tree components for Vue 3",
55
"author": "Gregg Rapoza <[email protected]>",
66
"license": "MIT",

src/components/TreeView.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</template>
5858

5959
<script setup>
60-
import { computed, nextTick, ref, readonly, onMounted, provide, toRef, watch } from 'vue'
60+
import { computed, nextTick, ref, readonly, onMounted, provide, toRef, watchEffect } from 'vue'
6161
import SelectionMode from '../enums/selectionMode.js';
6262
import { useIdGeneration } from '../composables/idGeneration.js'
6363
import { useTreeViewTraversal } from '../composables/treeViewTraversal.js'
@@ -224,11 +224,7 @@ const { spliceNodeList } = useTreeViewDataUpdates(model, metaModel);
224224
useTreeViewFilter(metaModel);
225225
226226
// Watch the model to make sure the metamodel is kept in sync
227-
watch([model, model.value], () => {
228-
// WARNINGS: For whatever reason, the Storybook stories don't fire this watch when model is updated unless the
229-
// model.value is also included in the watch. This is a workaround for that issue. I have no idea why this is happening.
230-
// However, it also (rightly) adds warnings in the console that model.value is not a valid watch source.
231-
227+
watchEffect(() => {
232228
model.value.forEach((node, index) => {
233229
const metaIndex = metaModel.value.findIndex((m) => m.data[m.idProperty] === node[m.idProperty]);
234230

src/components/TreeViewNode.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238

239239
<script setup>
240240
241-
import { computed, ref, toRef, watch } from 'vue'
241+
import { computed, ref, toRef, watchEffect } from 'vue'
242242
import { useNodeDataNormalizer } from '../composables/nodeDataNormalizer.js';
243243
import { useChildren } from '../composables/children/children.js';
244244
import { useTreeViewNodeChildren } from '../composables/children/treeViewNodeChildren.js';
@@ -412,9 +412,9 @@ const {
412412
} = useTreeViewNodeDragAndDrop(metaModel, treeId, emit);
413413
414414
// Watch the model children to make sure the metamodel is kept in sync
415-
watch([getChildren(metaModel), () => getChildren(metaModel)], () => {
415+
watchEffect(() => {
416416
// Patch the meta children to match the data children
417-
const metaChildren = metaModel.value.childMetaModels;
417+
const metaChildren = children.value;
418418
const dataChildren = getChildren(metaModel);
419419
420420
dataChildren.forEach((node, index) => {

0 commit comments

Comments
 (0)