refactor: use injected store so we can use a distinct instance not a global one

This commit is contained in:
Braks
2021-07-13 16:13:15 +02:00
parent 8f727a4d93
commit 6c9d88b09d
13 changed files with 327 additions and 217 deletions
+5 -7
View File
@@ -1,5 +1,3 @@
import { Store } from 'pinia';
import { clampPosition, clamp } from './index';
import {
@@ -13,8 +11,8 @@ import {
Box,
Connection,
FlowExportObject,
RevueFlowState,
NodeExtent
NodeExtent,
RevueFlowStore
} from '../types';
export const isEdge = (element: Node | Connection | Edge): element is Edge =>
@@ -138,7 +136,7 @@ export const pointToRendererPoint = (
return position;
};
export const onLoadProject = (currentStore: Store<'revue-flow', RevueFlowState>) => {
export const onLoadProject = (currentStore: RevueFlowStore) => {
return (position: XYPosition): XYPosition => {
return pointToRendererPoint(position, currentStore.transform, currentStore.snapToGrid, currentStore.snapGrid);
};
@@ -266,13 +264,13 @@ const parseElements = (nodes: Node[], edges: Edge[]): Elements => {
];
};
export const onLoadGetElements = (currentStore: Store<'revue-flow', RevueFlowState>) => {
export const onLoadGetElements = (currentStore: RevueFlowStore) => {
return (): Elements => {
return parseElements(currentStore.nodes || [], currentStore.edges || []);
};
};
export const onLoadToObject = (currentStore: Store<'revue-flow', RevueFlowState>) => {
export const onLoadToObject = (currentStore: RevueFlowStore) => {
return (): FlowExportObject => {
return {
elements: parseElements(currentStore.nodes || [], currentStore.edges || []),