devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
138 lines (136 loc) • 4.38 kB
JavaScript
/**
* DevExtreme (cjs/__internal/scheduler/appointments_new/utils/get_view_model_diff.js)
* Version: 25.2.7
* Build date: Tue May 05 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getViewModelDiff = void 0;
var _common = require("../../../../core/utils/common");
var _type_helpers = require("./type_helpers");
const getObjectToCompare = (item, includeDimensions) => {
const result = (0, _type_helpers.isCollectorViewModel)(item) ? {
allDay: item.allDay,
groupIndex: item.groupIndex,
items: item.items.length
} : {
allDay: item.allDay,
groupIndex: item.groupIndex,
direction: item.direction,
reduced: item.reduced,
partIndex: item.partIndex,
partTotalCount: item.partTotalCount,
rowIndex: item.rowIndex,
columnIndex: item.columnIndex
};
return includeDimensions ? Object.assign({}, result, {
left: item.left,
top: item.top,
height: item.height,
width: item.width
}) : result
};
const isAppointmentDataChanged = (appointmentData, appointmentDataSource) => {
const updatedAppointmentData = appointmentDataSource.getUpdatedAppointment();
if (updatedAppointmentData === appointmentData) {
return true
}
const updateAppointmentKeys = appointmentDataSource.getUpdatedAppointmentKeys();
return updateAppointmentKeys.some(item => appointmentData[item.key] === item.value)
};
function getArraysDiff(options) {
const {
a: a,
b: b,
match: match,
equal: equal,
canResize: canResize
} = options;
const n = a.length;
const m = b.length;
const dp = Array.from({
length: n + 1
}, () => new Array(m + 1).fill(0));
for (let i = 1; i <= n; i += 1) {
const ai = a[i - 1];
for (let j = 1; j <= m; j += 1) {
dp[i][j] = match(ai, b[j - 1]) ? dp[i - 1][j - 1] + 1 : Math.max(dp[i - 1][j], dp[i][j - 1])
}
}
const result = [];
let i = n;
let j = m;
while (i > 0 && j > 0) {
const ai = a[i - 1];
const bj = b[j - 1];
if (match(ai, bj)) {
if (equal(ai, bj)) {
result.push({
item: bj,
oldSortedIndex: ai.sortedIndex
})
} else if (canResize(ai, bj)) {
result.push({
item: bj,
needToResize: true,
oldSortedIndex: ai.sortedIndex
})
} else {
result.push({
item: ai,
needToRemove: true
});
result.push({
item: bj,
needToAdd: true
})
}
i -= 1;
j -= 1
} else if (dp[i - 1][j] >= dp[i][j - 1]) {
result.push({
item: ai,
needToRemove: true
});
i -= 1
} else {
result.push({
item: bj,
needToAdd: true
});
j -= 1
}
}
while (i > 0) {
result.push({
item: a[i - 1],
needToRemove: true
});
i -= 1
}
while (j > 0) {
result.push({
item: b[j - 1],
needToAdd: true
});
j -= 1
}
result.reverse();
return result
}
const getViewModelDiff = (oldViewModel, newViewModel, appointmentDataSource) => {
const result = getArraysDiff({
a: oldViewModel,
b: newViewModel,
match: (a, b) => a.itemData === b.itemData && !isAppointmentDataChanged(b.itemData, appointmentDataSource),
equal: (a, b) => (0, _common.equalByValue)(getObjectToCompare(a, true), getObjectToCompare(b, true)),
canResize: (a, b) => (0, _common.equalByValue)(getObjectToCompare(a, false), getObjectToCompare(b, false))
});
return result
};
exports.getViewModelDiff = getViewModelDiff;