Skip to content

Commit b01ae1f

Browse files
committed
fix: revert to watching all props in vue wrapper
1 parent edba02e commit b01ae1f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

docs/pages/custom-integration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Example based on vue and react:
2323
</template>
2424
2525
<script lang="ts" setup>
26-
import {shallowRef, useTemplateRef, watch} from 'vue';
26+
import { shallowRef, useTemplateRef, watchEffect } from 'vue';
2727
import SelectionArea, { SelectionEvent } from '@viselect/vanilla';
2828
2929
// Refs to the container and the instance
@@ -37,12 +37,12 @@ const start = (evt: SelectionEvent) => console.log('start', evt);
3737
const move = (evt: SelectionEvent) => console.log('move', evt);
3838
const stop = (evt: SelectionEvent) => console.log('stop', evt);
3939
40-
// Watch container and mount the instance
41-
watch(container, (element) => {
42-
if (element) {
40+
// Watch container as well as prop and mount instance
41+
watchEffect(() => {
42+
if (container.value) {
4343
instance.value?.destroy();
4444
instance.value = new SelectionArea({
45-
boundaries: element,
45+
boundaries: container.value,
4646
// ...your options
4747
});
4848

packages/vue/src/SelectionArea.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<script lang="ts" setup>
88
import SelectionArea, {SelectionEvent, PartialSelectionOptions} from '@viselect/vanilla';
9-
import {onBeforeUnmount, shallowRef, useTemplateRef, watch} from 'vue';
9+
import {onBeforeUnmount, shallowRef, useTemplateRef, watchEffect} from 'vue';
1010
1111
const emit = defineEmits<{
1212
(e: 'before-start', v: SelectionEvent): void;
@@ -24,11 +24,11 @@ const props = defineProps<{
2424
const container = useTemplateRef('container');
2525
const instance = shallowRef<SelectionArea | undefined>();
2626
27-
watch(container, (element) => {
28-
if (element) {
27+
watchEffect(() => {
28+
if (container.value) {
2929
instance.value?.destroy();
3030
instance.value = new SelectionArea({
31-
boundaries: element,
31+
boundaries: container.value,
3232
...props.options
3333
});
3434

0 commit comments

Comments
 (0)