provide id as ref object instead of string

This commit is contained in:
Laila Los
2023-11-06 16:54:44 +01:00
parent 684663360f
commit 3add9e7cd1
3 changed files with 16 additions and 16 deletions
@@ -243,7 +243,7 @@ export default {
const uid = unref(useUid("workflow-editor-"));
const id = ref(props.workflowId || uid);
const { connectionStore, stepStore, stateStore, commentStore } = provideScopedWorkflowStores(id.value);
const { connectionStore, stepStore, stateStore, commentStore } = provideScopedWorkflowStores(id);
const { comments } = storeToRefs(commentStore);
const { getStepIndex, steps } = storeToRefs(stepStore);
@@ -46,7 +46,7 @@ const errorMessage = ref("");
const { datatypesMapper } = useDatatypesMapper();
const { stateStore } = provideScopedWorkflowStores(props.id);
const { stateStore } = provideScopedWorkflowStores(ref(props.id));
stateStore.setScale(0.75);
+14 -14
View File
@@ -1,4 +1,4 @@
import { inject, onScopeDispose, provide } from "vue";
import { inject, onScopeDispose, provide, type Ref } from "vue";
import { useConnectionStore } from "@/stores/workflowConnectionStore";
import { useWorkflowCommentStore } from "@/stores/workflowEditorCommentStore";
@@ -15,14 +15,14 @@ import { useWorkflowStepStore } from "@/stores/workflowStepStore";
* @param workflowId the workflow to scope to
* @returns workflow Stores
*/
export function provideScopedWorkflowStores(workflowId: string) {
export function provideScopedWorkflowStores(workflowId: Ref<string>) {
provide("workflowId", workflowId);
const connectionStore = useConnectionStore(workflowId);
const stateStore = useWorkflowStateStore(workflowId);
const stepStore = useWorkflowStepStore(workflowId);
const commentStore = useWorkflowCommentStore(workflowId);
const toolbarStore = useWorkflowEditorToolbarStore(workflowId);
const connectionStore = useConnectionStore(workflowId.value);
const stateStore = useWorkflowStateStore(workflowId.value);
const stepStore = useWorkflowStepStore(workflowId.value);
const commentStore = useWorkflowCommentStore(workflowId.value);
const toolbarStore = useWorkflowEditorToolbarStore(workflowId.value);
onScopeDispose(() => {
connectionStore.$dispose();
@@ -51,19 +51,19 @@ export function provideScopedWorkflowStores(workflowId: string) {
* @returns workflow stores
*/
export function useWorkflowStores() {
const workflowId = inject("workflowId");
const workflowId = inject("workflowId") as Ref<string>;
if (typeof workflowId !== "string") {
if (typeof workflowId?.value !== "string") {
throw new Error(
"Workflow ID not provided by parent component. Use `provideScopedWorkflowStores` on a parent component."
);
}
const connectionStore = useConnectionStore(workflowId);
const stateStore = useWorkflowStateStore(workflowId);
const stepStore = useWorkflowStepStore(workflowId);
const commentStore = useWorkflowCommentStore(workflowId);
const toolbarStore = useWorkflowEditorToolbarStore(workflowId);
const connectionStore = useConnectionStore(workflowId.value);
const stateStore = useWorkflowStateStore(workflowId.value);
const stepStore = useWorkflowStepStore(workflowId.value);
const commentStore = useWorkflowCommentStore(workflowId.value);
const toolbarStore = useWorkflowEditorToolbarStore(workflowId.value);
return {
connectionStore,