-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from wsfe/feat/update-node-api
feat: add update node APIs
- Loading branch information
Showing
12 changed files
with
548 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<template> | ||
<button @click="handleClearChildren">Clear node-1 children</button> | ||
<button @click="handleSetChildren">Set node-1 children</button> | ||
<button @click="handleUpdateChildren">Update node-1 children</button> | ||
<div :style="{ height: '300px' }"> | ||
<VTree ref="tree" checkable selectable /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, onMounted, ref } from 'vue' | ||
import VTree from '@wsfe/vue-tree' | ||
const tree = ref() | ||
const children = Array.from({ length: 100000 }).map((_, i) => { | ||
return { | ||
title: `node-1-${i + 1}`, | ||
id: `node-1-${i + 1}`, | ||
} | ||
}) | ||
const data = [ | ||
{ | ||
title: 'node-1', | ||
id: 'node-1', | ||
children, | ||
}, | ||
{ | ||
title: 'node-2', | ||
id: 'node-2', | ||
children: [ | ||
{ | ||
title: 'node-2-1', | ||
id: 'node-2-1', | ||
}, | ||
], | ||
}, | ||
] | ||
onMounted(() => { | ||
tree.value.setData(data) | ||
}) | ||
const handleSetChildren = () => { | ||
tree.value.updateNode('node-1', { children }) | ||
} | ||
const handleClearChildren = () => { | ||
tree.value.updateNode('node-1', { children: [] }) | ||
} | ||
const handleUpdateChildren = () => { | ||
tree.value.updateNode('node-1', { | ||
children: children.map((child) => { | ||
return { | ||
...child, | ||
title: `${child.title} ${Date.now()}`, | ||
checked: true, | ||
} | ||
}) | ||
}) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
button { | ||
border: 1px solid lightgray; | ||
border-radius: 8px; | ||
padding-left: 10px; | ||
padding-right: 10px; | ||
margin-right: 20px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<template> | ||
<button @click="handleUpdateCount">Update node-1 count</button> | ||
<VTree ref="tree"> | ||
<template #node="{ node }"> | ||
<span>{{ node.title }}</span> | ||
<span v-if="typeof node.count === 'number'"> | ||
Count: {{ node.count }} | ||
</span> | ||
</template> | ||
</VTree> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, ref } from 'vue' | ||
import VTree from '@wsfe/vue-tree' | ||
const tree = ref() | ||
const data = [ | ||
{ | ||
title: 'node-1', | ||
id: 'node-1', | ||
count: 0, | ||
children: [ | ||
{ | ||
title: 'node-1-1', | ||
id: 'node-1-1', | ||
}, | ||
{ | ||
title: 'node-1-2', | ||
id: 'node-1-2', | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'node-2', | ||
id: 'node-2', | ||
children: [ | ||
{ | ||
title: 'node-2-1', | ||
id: 'node-2-1', | ||
}, | ||
], | ||
}, | ||
] | ||
onMounted(() => { | ||
tree.value.setData(data) | ||
}) | ||
const handleUpdateCount = () => { | ||
const key = 'node-1' | ||
const currentCount = tree.value.getNode(key).count | ||
tree.value.updateNode(key, { count: currentCount + 1 }) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
button { | ||
border: 1px solid lightgray; | ||
border-radius: 8px; | ||
padding-left: 10px; | ||
padding-right: 10px; | ||
margin-right: 20px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<template> | ||
<button @click="handleUpdateSingleNode">Update node-1</button> | ||
<button @click="handleUpdateMultipleNode">Update node-1 & node-2</button> | ||
<VTree ref="tree" /> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, onMounted, ref } from 'vue' | ||
import VTree from '@wsfe/vue-tree' | ||
const tree = ref() | ||
const data = [ | ||
{ | ||
title: 'node-1', | ||
id: 'node-1', | ||
children: [ | ||
{ | ||
title: 'node-1-1', | ||
id: 'node-1-1', | ||
}, | ||
{ | ||
title: 'node-1-2', | ||
id: 'node-1-2', | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'node-2', | ||
id: 'node-2', | ||
children: [ | ||
{ | ||
title: 'node-2-1', | ||
id: 'node-2-1', | ||
}, | ||
], | ||
}, | ||
] | ||
onMounted(() => { | ||
tree.value.setData(data) | ||
}) | ||
const count = ref(0) | ||
const handleUpdateSingleNode = () => { | ||
count.value++ | ||
tree.value.updateNode('node-1', { title: `node-1 - ${count.value}` }) | ||
} | ||
const handleUpdateMultipleNode = () => { | ||
count.value++ | ||
tree.value.updateNodes([ | ||
{ | ||
id: 'node-1', | ||
title: `node-1 - ${count.value}`, | ||
}, | ||
{ | ||
id: 'node-2', | ||
title: `node-2 - ${count.value}`, | ||
}, | ||
]) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
button { | ||
border: 1px solid lightgray; | ||
border-radius: 8px; | ||
padding-left: 10px; | ||
padding-right: 10px; | ||
margin-right: 20px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.