Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepMixIn causes valid properties to be merged by 'undefined` values in onConflict="merge" strategy #537

Open
zeesulehria opened this issue Apr 23, 2019 · 0 comments

Comments

@zeesulehria
Copy link

Description

If I have a record in cache with valid properites, and later on if its gets 'merged with another version of this record that has some of the properties 'undefined, valid properties present in cache earlier gets over-written with 'undefined' values in deepMixIn() function.

Here is current implementation of this function:

deepMixIn: function deepMixIn(dest, source) {
      if (source) {
        for (var key in source) {
          var value = source[key];
          var existing = dest[key];
          if (isPlainObject(value) && isPlainObject(existing)) {
            utils.deepMixIn(existing, value);
          } else  {
            dest[key] = value;
          }
        }
      }
      return dest;
    },

And we can fix it by changing it like:

deepMixIn: function deepMixIn(dest, source) {
      if (source) {
        for (var key in source) {
          var value = source[key];
          var existing = dest[key];
          if (isPlainObject(value) && isPlainObject(existing)) {
            utils.deepMixIn(existing, value);
          } else if (typeof value !== 'undefined') {
            dest[key] = value;
          }
        }
      }
      return dest;
    },

Environment

  • js-data version:
    "js-data": "^3.0.5",
    "js-data-http": "^3.0.1",
  • node or browser version: v10.7.0
  • operating system: macOS

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant