Skip to content

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

Open
@zeesulehria

Description

@zeesulehria

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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