mirror of
https://github.com/plankanban/planka.git
synced 2025-12-26 17:25:03 +03:00
Project managers, board members, auto-update after reconnection, refactoring
This commit is contained in:
27
client/src/utils/merge-records.js
Normal file
27
client/src/utils/merge-records.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const mergeRecords = (target, ...sources) => {
|
||||
if (sources.length === 0) {
|
||||
return target;
|
||||
}
|
||||
|
||||
const source = sources.shift();
|
||||
|
||||
if (!target || !source) {
|
||||
return mergeRecords(target || source, ...sources);
|
||||
}
|
||||
|
||||
const nextTarget = [...target];
|
||||
|
||||
source.forEach((sourceRecord) => {
|
||||
const index = nextTarget.findIndex((targetRecord) => targetRecord.id === sourceRecord.id);
|
||||
|
||||
if (index >= 0) {
|
||||
Object.assign(nextTarget[index], sourceRecord);
|
||||
} else {
|
||||
nextTarget.push(sourceRecord);
|
||||
}
|
||||
});
|
||||
|
||||
return mergeRecords(nextTarget, ...sources);
|
||||
};
|
||||
|
||||
export default mergeRecords;
|
||||
Reference in New Issue
Block a user