TehShrike / deepmerge

A library for deep (recursive) merging of Javascript objects
MIT License
2.75k stars 216 forks source link

It need filter on merge #258

Open alexk400 opened 1 year ago

alexk400 commented 1 year ago

Hi

i was using react-data-table-component package which is uses deep merge to custom merge styles to default styles. it do not accept anonymous function because merge do not have filter.

Basically every time it replace text it need to check if its a function. Filter passed job is to have a flag to say check for function. Tomorrow filter can be something else. Today just see if its a function and excecute it and replace that value with original value.

This is your method `function mergeObject(target, source, options) { var destination = {}; if (options.isMergeableObject(target)) { getKeys(target).forEach(function(key) { destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); }); } getKeys(source).forEach(function(key) { if (propertyIsUnsafe(target, key)) { return }

    if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
        destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
    } else {
        destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
    }

//alexk code begin var newdest=destination[key]; if(typeof newdest === 'function') destination[key]=newdest(); //alexk code ends });

return destination

}`