mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-26 17:07:58 +03:00
30 lines
610 B
JavaScript
30 lines
610 B
JavaScript
const { MutateCollection, EfficientInPlaceDeepmerge } = require("./util");
|
|
|
|
function DoesMatchCriteria(element, mutation) {
|
|
for (const [key, value] of Object.entries(mutation.match)) {
|
|
if (element[key] !== value) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function ApplyMutations(name, mutations) {
|
|
MutateCollection(name, (collection) => {
|
|
for (const element of collection) {
|
|
for (const mutation of mutations) {
|
|
if (DoesMatchCriteria(element, mutation)) {
|
|
EfficientInPlaceDeepmerge(element, mutation.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
return collection;
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
ApplyMutations,
|
|
};
|