Skip to content

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

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

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy