mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-06 23:09:08 +00:00
refactor: improve merge logic
This commit is contained in:
committed by
Carlos Valente
parent
08b8e73393
commit
a5daa76616
@@ -7,24 +7,27 @@ export function safeMerge(existing: DatabaseModel, newData: Partial<DatabaseMode
|
||||
const deepExisting = structuredClone(existing);
|
||||
const deepNewData = structuredClone(newData);
|
||||
|
||||
// destructure each property to simplify merging not provided ie: ...{} has no effect
|
||||
const {
|
||||
rundowns = {},
|
||||
project = {},
|
||||
settings = {},
|
||||
viewSettings = {},
|
||||
urlPresets = deepExisting.urlPresets,
|
||||
customFields = deepExisting.customFields,
|
||||
automation = deepExisting.automation,
|
||||
urlPresets = [],
|
||||
customFields = {},
|
||||
automation,
|
||||
} = deepNewData;
|
||||
|
||||
return {
|
||||
...deepExisting,
|
||||
rundowns: { ...existing.rundowns, ...rundowns },
|
||||
project: { ...deepExisting.project, ...project },
|
||||
settings: { ...deepExisting.settings, ...settings },
|
||||
viewSettings: { ...deepExisting.viewSettings, ...viewSettings },
|
||||
urlPresets: urlPresets ?? deepExisting.urlPresets,
|
||||
customFields: customFields ?? deepExisting.customFields,
|
||||
automation: { ...deepExisting.automation, ...automation },
|
||||
// URL presets are independent and we can append them together
|
||||
urlPresets: [...deepExisting.urlPresets, ...urlPresets],
|
||||
// custom fields can be merged
|
||||
customFields: { ...deepExisting.customFields, ...customFields },
|
||||
// trigger and automation are coupled and cannot be changed individually so we replace the whole automation
|
||||
automation: automation ?? deepExisting.automation,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user