update: Add effect scope to useZoomPanHelper.ts
* Easier cleanup after zoompanhelper has been initialized
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { zoomIdentity } from 'd3-zoom';
|
||||
import { computed, inject } from 'vue';
|
||||
import { computed, effectScope, inject } from 'vue';
|
||||
import { createEventHook, EventHookOn, until } from '@vueuse/core';
|
||||
import { Selection, ZoomBehavior } from 'd3';
|
||||
import { getRectOfNodes, pointToRendererPoint, getTransformForBounds } from '../utils/graph';
|
||||
@@ -10,6 +10,9 @@ const DEFAULT_PADDING = 0.1;
|
||||
const useZoomPanHelper = (): { onReady: EventHookOn<ZoomPanHelperFunctions> } => {
|
||||
const zoomPanHelperEvent = createEventHook<ZoomPanHelperFunctions>();
|
||||
const store = inject<RevueFlowStore>('store')!;
|
||||
|
||||
const scope = effectScope();
|
||||
scope.run(() => {
|
||||
const d3Zoom = computed(() => store.d3Zoom);
|
||||
const d3Selection = computed(() => store.d3Selection);
|
||||
|
||||
@@ -76,7 +79,10 @@ const useZoomPanHelper = (): { onReady: EventHookOn<ZoomPanHelperFunctions> } =>
|
||||
} else {
|
||||
throw Error('D3 could not be initialized.');
|
||||
}
|
||||
scope.stop();
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
onReady: zoomPanHelperEvent.on
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user