Skip to content

Commit

Permalink
Add comments, order logical
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj committed May 8, 2024
1 parent 893339b commit a562dd9
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useFieldDetailStore = defineStore({
/** What field we're currently editing ("+"" for new) */
editing: '+' as string,

/** Full field data with edits */
/** Full field data with edits */
field: {
field: undefined,
type: undefined,
Expand Down Expand Up @@ -167,12 +167,7 @@ export const useFieldDetailStore = defineStore({

const { field: fieldUpdates, items: itemUpdates, ...restUpdates } = updates;

mergeWith(state, restUpdates, (_, srcValue, key, object) => {
if (Array.isArray(srcValue)) return srcValue;
if (srcValue === undefined) object[key] = undefined;
return;
});

// Handle `field` updates, shallow merge and mirror to `fieldUpdates`
if (fieldUpdates) {
const { schema: schemaUpdates, meta: metaUpdates, ...restFieldUpdates } = fieldUpdates;

Expand All @@ -190,9 +185,19 @@ export const useFieldDetailStore = defineStore({
}
}

// Handle `item` updates, allowing full replacements
if (itemUpdates) {
state.items = itemUpdates as (typeof this.$state)['items'];
}

// Handle remaining updates, deep merge
mergeWith(state, restUpdates, (_, srcValue, key, object) => {
// Override arrays instead of merging
if (Array.isArray(srcValue)) return srcValue;
// Allow properties to be resettable
if (srcValue === undefined) object[key] = undefined;
return;
});
});
},
async save() {
Expand Down

0 comments on commit a562dd9

Please sign in to comment.