Skip to content

Fix the watch source warning #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grapoza/vue-tree",
"version": "6.1.0",
"version": "6.1.1",
"description": "Tree components for Vue 3",
"author": "Gregg Rapoza <[email protected]>",
"license": "MIT",
Expand Down
8 changes: 2 additions & 6 deletions src/components/TreeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</template>

<script setup>
import { computed, nextTick, ref, readonly, onMounted, provide, toRef, watch } from 'vue'
import { computed, nextTick, ref, readonly, onMounted, provide, toRef, watchEffect } from 'vue'
import SelectionMode from '../enums/selectionMode.js';
import { useIdGeneration } from '../composables/idGeneration.js'
import { useTreeViewTraversal } from '../composables/treeViewTraversal.js'
Expand Down Expand Up @@ -224,11 +224,7 @@ const { spliceNodeList } = useTreeViewDataUpdates(model, metaModel);
useTreeViewFilter(metaModel);

// Watch the model to make sure the metamodel is kept in sync
watch([model, model.value], () => {
// WARNINGS: For whatever reason, the Storybook stories don't fire this watch when model is updated unless the
// model.value is also included in the watch. This is a workaround for that issue. I have no idea why this is happening.
// However, it also (rightly) adds warnings in the console that model.value is not a valid watch source.

watchEffect(() => {
model.value.forEach((node, index) => {
const metaIndex = metaModel.value.findIndex((m) => m.data[m.idProperty] === node[m.idProperty]);

Expand Down
6 changes: 3 additions & 3 deletions src/components/TreeViewNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@

<script setup>

import { computed, ref, toRef, watch } from 'vue'
import { computed, ref, toRef, watchEffect } from 'vue'
import { useNodeDataNormalizer } from '../composables/nodeDataNormalizer.js';
import { useChildren } from '../composables/children/children.js';
import { useTreeViewNodeChildren } from '../composables/children/treeViewNodeChildren.js';
Expand Down Expand Up @@ -412,9 +412,9 @@ const {
} = useTreeViewNodeDragAndDrop(metaModel, treeId, emit);

// Watch the model children to make sure the metamodel is kept in sync
watch([getChildren(metaModel), () => getChildren(metaModel)], () => {
watchEffect(() => {
// Patch the meta children to match the data children
const metaChildren = metaModel.value.childMetaModels;
const metaChildren = children.value;
const dataChildren = getChildren(metaModel);

dataChildren.forEach((node, index) => {
Expand Down