Skip to content

Commit

Permalink
fix: Add recursive merge for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestreety committed Oct 8, 2024
1 parent 6d90f5a commit 2b453f4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Resources/Public/JavaScript/ModuleDataListing.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ define([

// Setting config - merges options
config: function(options = {}) {
ModuleDataListing.settings = Object.assign({}, ModuleDataListing.settings, options);
ModuleDataListing.settings = ModuleDataListing.utility.mergeObjects(ModuleDataListing.settings, options);
}
};

Expand Down Expand Up @@ -165,7 +165,7 @@ define([
// Initialise the datatable
const table = $(ModuleDataListing.settings.tableSelector)
.DataTable(
Object.assign({}, ModuleDataListing.settings.dataTable, settings)
ModuleDataListing.utility.mergeObjects(ModuleDataListing.settings.dataTable, settings)
);

// Add listener for search box to update storage
Expand Down Expand Up @@ -256,5 +256,24 @@ define([
},
}

ModuleDataListing.utility = {
// Filter setup
mergeObjects: function (obj1, obj2) {
const result = { ...obj1 };

for (let key in obj2) {
if (obj2.hasOwnProperty(key)) {
if (obj2[key] instanceof Object && obj1[key] instanceof Object) {
result[key] = ModuleDataListing.utility.mergeObjects(obj1[key], obj2[key]);
} else {
result[key] = obj2[key];
}
}
}

return result;
}
}

return ModuleDataListing;
});

0 comments on commit 2b453f4

Please sign in to comment.