Skip to content

Commit f362fe7

Browse files
committed
refactor: use viewIDs computed property instead of Object.keys(viewByID)
1 parent b221dd8 commit f362fe7

4 files changed

Lines changed: 12 additions & 24 deletions

File tree

‎src/composables/useSyncWindowing.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function useSyncWindowing() {
1313
isUpdating = true;
1414
try {
1515
const config = windowingStore.getConfig(viewID, dataID);
16-
Object.keys(viewStore.viewByID)
16+
viewStore.viewIDs
1717
.filter((id) => id !== viewID)
1818
.forEach((vid) => {
1919
windowingStore.updateConfig(vid, dataID, config);

‎src/store/tools/paint.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const usePaintToolStore = defineStore('paint', () => {
5757
const currentViewIDs = computed(() => {
5858
const imageID = unref(currentImageID);
5959
if (imageID) {
60-
return Object.keys(viewStore.viewByID).filter(
60+
return viewStore.viewIDs.filter(
6161
(viewID) => !!viewSliceStore.getConfig(viewID, imageID)
6262
);
6363
}

‎src/store/view-configs/common.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ const serializeViewConfig = <
2424
// eslint-disable-next-line no-param-reassign
2525
view.config = {};
2626
}
27-
const configForData = ensureDefault(dataID, view.config, {} as ViewConfig);
27+
const configForData = ensureDefault(
28+
dataID,
29+
view.config,
30+
{} as ViewConfig
31+
);
2832
configForData[viewConfigStateKey] = viewConfig as ViewConfig[K];
2933
}
3034
});

‎src/store/views.ts‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export const useViewStore = defineStore('view', () => {
8888
return views;
8989
});
9090

91+
const viewIDs = computed(() => Object.keys(viewByID));
92+
9193
function getView(id: Maybe<string>) {
9294
if (!id) return null;
9395
return viewByID[id] ?? null;
@@ -175,7 +177,7 @@ export const useViewStore = defineStore('view', () => {
175177
}
176178

177179
function setDataForAllViews(dataID: Maybe<string>) {
178-
Object.keys(viewByID).forEach((viewID) => {
180+
viewIDs.value.forEach((viewID) => {
179181
setDataForView(viewID, dataID);
180182
});
181183
}
@@ -206,7 +208,7 @@ export const useViewStore = defineStore('view', () => {
206208
isActiveViewMaximized.value = manifest.isActiveViewMaximized;
207209
layoutSlots.value = manifest.layoutSlots;
208210

209-
Object.keys(viewByID).forEach((key) => {
211+
viewIDs.value.forEach((key) => {
210212
delete viewByID[key];
211213
});
212214

@@ -218,25 +220,6 @@ export const useViewStore = defineStore('view', () => {
218220
});
219221
}
220222

221-
// deserialize(views: View[], dataIDMap: Record<string, string>) {
222-
// const viewConfigStore = useViewConfigStore();
223-
224-
// views.forEach((view) => {
225-
// const viewID = view.id;
226-
227-
// const viewSpec = {
228-
// viewType: view.type,
229-
// props: view.props,
230-
// };
231-
232-
// this.viewSpecs[viewID] = viewSpec;
233-
234-
// // Now delegate the deserialization of the view config
235-
// const { config } = view;
236-
// viewConfigStore.deserialize(viewID, config, dataIDMap);
237-
// });
238-
// },
239-
240223
// initialization
241224

242225
DefaultLayoutSlots.forEach((viewInit) => {
@@ -253,6 +236,7 @@ export const useViewStore = defineStore('view', () => {
253236
return layout.value;
254237
}),
255238
visibleViews,
239+
viewIDs,
256240
activeView,
257241
viewByID,
258242
getView,

0 commit comments

Comments
 (0)