rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

isMergableObject returns true for an empty object #82

Open ramivalta opened 8 years ago

ramivalta commented 8 years ago
      function addToResult(currentObj, otherObj, key) {
      var immutableValue = Immutable(otherObj[key]);
      var mergerResult = merger && merger(currentObj[key], immutableValue, config);
      var currentValue = currentObj[key];

      console.log("IS NEW OBJECT MERGABLE", isMergableObject(new Object()));

  -> seamless-immutable.js:306 IS NEW OBJECT MERGABLE true

In my production build currentValue is sometimes an empty object, and with deep merge enabled we error out when trying to call merge() on said object. In dev mode this never seems to happen.

I've worked around this with an additional check to isMergableObject which checks that Object.keys(target).length > 0. If this seems like an acceptable fix I'd love to submit a PR.

rtfeldman commented 8 years ago

Sounds good! Nice catch, and would love a PR! :+1:

Can you @-mention me on the PR?