benjamine / jsondiffpatch

Diff & patch JavaScript objects
MIT License
4.78k stars 466 forks source link

Ignore functions instead of throwing error? #284

Open ipip2005 opened 4 years ago

ipip2005 commented 4 years ago

I understand that jsondiffpatch doesn't support diffing objects that have functions, I'm wondering if there is a way to simply ignore those functions instead of throwing error?

I tried using propertyFilter option like below but didn't help

      propertyFilter: function (name, context) {
        return typeof context.left !== 'function' && typeof context.right !== 'function'
      }

Maybe we can filter the objects before calling diff but that extra CPU cost will be too much for us.

Any ideas? I'm open to raise a PR to that.

schwarzeszeux commented 1 year ago

I realize this is old but in case someone stumbles this issue:

Your property filter would need to look like this.

propertyFilter: function (name, context) {
        return typeof context.left[name] !== 'function' && typeof context.right[name] !== 'function'
      }

context.left and context.right aren't the objects that are compared but rather their parents.