devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
64 lines (63 loc) • 2.07 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/appointments/utils/get_view_model_diff.js)
* Version: 26.1.3
* Build date: Wed Jun 10 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
equalByValue
} from "../../../../core/utils/common";
import {
getArraysDiff
} from "./get_arrays_diff";
const getObjectToCompare = item => {
if ("isAgendaModel" in item) {
return {}
}
if ("items" in item) {
return {
allDay: item.allDay,
groupIndex: item.groupIndex,
top: item.top,
left: item.left
}
}
return {
allDay: item.allDay,
groupIndex: item.groupIndex,
direction: item.direction,
left: item.left,
top: item.top,
height: item.height,
width: item.width,
reduced: item.reduced,
partIndex: item.partIndex,
partTotalCount: item.partTotalCount,
rowIndex: item.rowIndex,
columnIndex: item.columnIndex
}
};
const getItemsLengthToCompare = item => {
if ("items" in item) {
return {
items: item.items.length
}
}
return {}
};
const isDataChanged = (data, appointmentDataSource) => {
const updatedData = appointmentDataSource.getUpdatedAppointment();
return updatedData === data || appointmentDataSource.getUpdatedAppointmentKeys().some(item => data[item.key] === item.value)
};
export const getViewModelDiff = (viewModelOld, viewModelNext, appointmentDataSource) => {
const equal = (a, b) => equalByValue(getObjectToCompare(a), getObjectToCompare(b));
const result = getArraysDiff(viewModelOld, viewModelNext, (a, b) => {
if ("items" in a && "items" in b) {
return equal(a, b)
}
return a.itemData === b.itemData && !isDataChanged(a.itemData, appointmentDataSource)
}, equal, (a, b) => equalByValue(getItemsLengthToCompare(a), getItemsLengthToCompare(b)));
return result
};