Skip to content

Commit

Permalink
fix: revert to watching all props in vue wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Jan 20, 2025
1 parent edba02e commit b01ae1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions docs/pages/custom-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Example based on vue and react:
</template>
<script lang="ts" setup>
import {shallowRef, useTemplateRef, watch} from 'vue';
import { shallowRef, useTemplateRef, watchEffect } from 'vue';
import SelectionArea, { SelectionEvent } from '@viselect/vanilla';
// Refs to the container and the instance
Expand All @@ -37,12 +37,12 @@ const start = (evt: SelectionEvent) => console.log('start', evt);
const move = (evt: SelectionEvent) => console.log('move', evt);
const stop = (evt: SelectionEvent) => console.log('stop', evt);
// Watch container and mount the instance
watch(container, (element) => {
if (element) {
// Watch container as well as prop and mount instance
watchEffect(() => {
if (container.value) {
instance.value?.destroy();
instance.value = new SelectionArea({
boundaries: element,
boundaries: container.value,
// ...your options
});
Expand Down
8 changes: 4 additions & 4 deletions packages/vue/src/SelectionArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<script lang="ts" setup>
import SelectionArea, {SelectionEvent, PartialSelectionOptions} from '@viselect/vanilla';
import {onBeforeUnmount, shallowRef, useTemplateRef, watch} from 'vue';
import {onBeforeUnmount, shallowRef, useTemplateRef, watchEffect} from 'vue';
const emit = defineEmits<{
(e: 'before-start', v: SelectionEvent): void;
Expand All @@ -24,11 +24,11 @@ const props = defineProps<{
const container = useTemplateRef('container');
const instance = shallowRef<SelectionArea | undefined>();
watch(container, (element) => {
if (element) {
watchEffect(() => {
if (container.value) {
instance.value?.destroy();
instance.value = new SelectionArea({
boundaries: element,
boundaries: container.value,
...props.options
});
Expand Down

0 comments on commit b01ae1f

Please sign in to comment.