Skip to content

Commit

Permalink
Fix vue set+del when imported explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Oct 23, 2023
1 parent 4010617 commit a5be29e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
4 changes: 1 addition & 3 deletions client/src/components/Form/FormInputs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
</template>

<script>
import { set } from "vue";
import { matchCase } from "@/components/Form/utilities";
import FormCard from "./FormCard.vue";
Expand Down Expand Up @@ -147,7 +145,7 @@ export default {
repeatInsert(input) {
const newInputs = structuredClone(input.inputs);
set(input, "cache", input.cache ?? []);
input.cache = input.cache ?? [];
input.cache.push(newInputs);
this.onChangeForm();
Expand Down
10 changes: 5 additions & 5 deletions client/src/stores/collectionAttributesStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import { computed, del, ref, set } from "vue";
import { computed, ref } from "vue";

import { DatasetCollectionAttributes } from "./services";
import { fetchCollectionAttributes } from "./services/datasetCollection.service";
Expand All @@ -11,7 +11,7 @@ export const useCollectionAttributesStore = defineStore("collectionAttributesSto
const getAttributes = computed(() => {
return (hdcaId: string) => {
if (!storedAttributes.value[hdcaId]) {
set(storedAttributes.value, hdcaId, {});
storedAttributes.value[hdcaId] = {};
fetchAttributes({ hdcaId });
}
return storedAttributes.value[hdcaId];
Expand All @@ -25,13 +25,13 @@ export const useCollectionAttributesStore = defineStore("collectionAttributesSto
});

async function fetchAttributes(params: { hdcaId: string }) {
set(loadingAttributes.value, params.hdcaId, true);
loadingAttributes.value[params.hdcaId] = true;
try {
const attributes = await fetchCollectionAttributes(params);
set(storedAttributes.value, params.hdcaId, attributes);
storedAttributes.value[params.hdcaId] = attributes;
return attributes;
} finally {
del(loadingAttributes.value, params.hdcaId);
delete loadingAttributes.value[params.hdcaId];
}
}

Expand Down
18 changes: 9 additions & 9 deletions client/src/stores/collectionElementsStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import { computed, del, ref, set } from "vue";
import { computed, ref } from "vue";

import { CollectionEntry, DCESummary, HDCASummary, HistoryContentItemBase, isHDCA } from "./services";
import { fetchCollectionDetails, fetchElementsFromCollection } from "./services/datasetCollection.service";
Expand Down Expand Up @@ -79,7 +79,7 @@ export const useCollectionElementsStore = defineStore("collectionElementsStore",
// Adjust the offset to the first missing element
params.offset += firstMissingIndexInRange;

set(loadingCollectionElements.value, collectionKey, true);
loadingCollectionElements.value[collectionKey] = true;
// Mark all elements in the range as fetching
params.storedElements
.slice(params.offset, params.offset + params.limit)
Expand All @@ -91,23 +91,23 @@ export const useCollectionElementsStore = defineStore("collectionElementsStore",
});
// Update only the elements that were fetched
params.storedElements.splice(params.offset, fetchedElements.length, ...fetchedElements);
set(storedCollectionElements.value, collectionKey, params.storedElements);
storedCollectionElements.value[collectionKey] = params.storedElements;
} finally {
del(loadingCollectionElements.value, collectionKey);
delete loadingCollectionElements.value[collectionKey];
}
}

async function loadCollectionElements(collection: CollectionEntry) {
const elements = await fetchElementsFromCollection({ entry: collection });
set(storedCollectionElements.value, getCollectionKey(collection), elements);
storedCollectionElements.value[getCollectionKey(collection)] = elements;
}

function saveCollections(historyContentsPayload: HistoryContentItemBase[]) {
const collectionsInHistory = historyContentsPayload.filter(
(entry) => entry.history_content_type === "dataset_collection"
) as HDCASummary[];
for (const collection of collectionsInHistory) {
set<HDCASummary>(storedCollections.value, collection.id, collection);
storedCollections.value[collection.id] = collection;
}
}

Expand All @@ -120,13 +120,13 @@ export const useCollectionElementsStore = defineStore("collectionElementsStore",
}

async function fetchCollection(params: { id: string }) {
set(loadingCollectionElements.value, params.id, true);
loadingCollectionElements.value[params.id] = true;
try {
const collection = await fetchCollectionDetails({ hdcaId: params.id });
set(storedCollections.value, collection.id, collection);
storedCollections.value[collection.id] = collection;
return collection;
} finally {
del(loadingCollectionElements.value, params.id);
delete loadingCollectionElements.value[params.id];
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/stores/workflowStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";
import { defineStore } from "pinia";
import { computed, ref, set } from "vue";
import { computed, ref } from "vue";

import { getAppRoot } from "@/onload/loadConfig";
import type { Steps } from "@/stores/workflowStepStore";
Expand Down Expand Up @@ -58,7 +58,7 @@ export const useWorkflowStore = defineStore("workflowStore", () => {

const { data } = await promise;

set(workflowsByInstanceId.value, workflowId, data as Workflow);
workflowsByInstanceId.value[workflowId] = data as Workflow;
}

workflowDetailPromises.delete(workflowId);
Expand Down

0 comments on commit a5be29e

Please sign in to comment.