Giter Site home page Giter Site logo

deep-assign's Issues

Why should this module not be used?

The github description says [DON'T USE THIS MODULE PLEASE] but the readme doesn't say why not, and looking at the open issues doesn't make it clear either.

It would be good to put a sentence or two in the readme that says what's wrong with the module.

Deep assigning objects with different property types

I have to assign an object to another that could have prop of different kind.

In this example:

var assign = require('deep-assign');
assign({ prop: 'test1' }, { prop: ['u'] });

deep-assign try to set string characters to elements of the ['u'] array, and it throws
TypeError: Cannot assign to read only property '0' of [object String].
You can test it on tonicdev

I was instead expecting to obtain as result { prop: ['u'] }. That is, I was expecting the whole target prop to be overwritten by the source prop, being it a string and not an object.

Is this by design? If not , I could write a PR to implement the expectation I explain.

Source object get manipulated

Node version: 7.3.0

var deepAssign = require('deep-assign')
var o1 = {a: {b: 2}, d: {e: 5}}
var o2 = {a: {c: 3}, d: {f: 6}}
var o3 = deepAssign({}, o1, o2)
console.log(o3) // { a: { b: 2, c: 3 }, d: { e: 5, f: 6 } }
console.log(o1) // { a: { b: 2, c: 3 }, d: { e: 5, f: 6 } }

Source object should be kept intact, like Object.assign.

Does not work with sealed objects

See ES6 Code below:

class Model {
  constructor(props) {
    this.init();

    Object.seal(this);

    if (props) {
      deepAssign(this, props);
    }
  }

  init() {
    Object.defineProperties(this, {
      one: {
        value: null,
        writable: true,
        enumerable: true
      },
      two: {
        value: {},
        writable: true,
        enumerable: true
      }
    });
    Object.defineProperties(this.two, {
      three: {
        value: null,
        writable: true,
        enumerable: true
      },
      four: {
        value: null,
        writable: true,
        enumerable: true
      }
    });
  }
}

console.log(new Model({one: 'foo', two: {three: 'bar', four: 'baz', five: 'shouldn\'t appear'}, six: 'won\'t appear'}));

Assigning an array shorter than previous one results in merged array

I have encountered this problem when I tried to remove an object from an array and re-assign it to an object.

I have broken down the problem into this simple example:

const deepAssign = require('deep-assign');

const result = deepAssign({}, {
  a: [1, 2]
}, {
  a: [3]
});
console.log(result.a) // => [3, 2]

I expected result.a to be [3] instead.
The native Object.assign from v8 yields a different result:

const result = Object.assign({}, {
  a: [1, 2]
}, {
  a: [3]
});
console.log(result.a) // => [3]

This leads me to believe that this is a bug in deep-assign.

regular expressions are being ignored

regular expressions are ignored.

console.log(deepAssign({
	str: "a", reg: /a/
}, {
	str: "b", reg: /b/
})); // results in { str: 'b', reg: /a/ } instead of { str: 'b', reg: /b/ }

it mutates *some* of the sources

Is this the correct behaviour...?

let a = {x:{}}
let b = {x: {y: 1}}
let c = {x: {y: 2}}
deepAssign({}, a, b, c)
// { x: { y: 2 } }

console.log(a)
// { x: { y: 2 } }  <-- mutated!
console.log(b)
// { x: { y: 1 } }
console.log(c)
// { x: { y: 2 } }

It's quite a dangerous thing to mutate the sources, but if that's what this lib wants to be, shouldn't it mutate b too?

deep assign and functions

Hello,

When i try using deep-assign on an object referencing functions i get strange results.

Here is my example:

var deepAssign = require('deep-assign');
function test1() {
    console.log('test1')
};

function test2() {
    console.log('test2')
};

var classic = Object.assign(
    {
        a:test1,
    },{
        a:test2
    }
);
var deep = deepAssign(
    {
        a:test1,
    },{
        a: test2,
    }
);

console.log('classic assign' ,classic); // should be { a: test2 } and is { a: test2 }
console.log('deep assign', deep); // should be { a: test2 } but is { a: test1 }
console.log('is property a equal in classic and deep?', classic.a === deep.a) // should be true but is false

You can test this code here: https://runkit.com/belgac/582475d188bb01001414cdc5

Is this normal or should this be fixed?

Set not being overwritten

const assign = require('deep-assign')

const foo = {
  keys: new Set(['123456'])
}

const bar = assign({}, {keys: new Set()}, foo)

console.log('foo.keys.size = ', foo.keys.size)
console.log('bar.keys.size = ', bar.keys.size)

console.log('foo.keys.has(123456) = ', foo.keys.has('123456'))
console.log('bar.keys.has(123456) = ', bar.keys.has('123456'))

Yields:

foo.keys.size =  1
bar.keys.size =  0
foo.keys.has(123456) =  true
bar.keys.has(123456) =  false

property with null value in source object not overwriting to same property in target object

Hi Dev,
Following is not working correct:

var deepAssign = require("deep-assign");
deepAssign({}, {Lat: null, Lon: null}, {Lat: null, Lon: 2})

output is:
{Lon: 2}

It must be:
{Lat: null, Lon 2}

Due to this weird issue, my form validation is failing as Lat property is totally missing from output.
If I use Object.assign, it works correctly.
Can you plz guide me what is wrong?

Deep-copying arrays

Is this lib meant to deep-copy arrays? I expected it to, but it doesn't. Here's a failing test.

test('deep-copies arrays', t => {

    // original object with an array
    var original = {arr: ['one', 'two', 'three']};

    // deep-duplicate it
    var dupe = fn({}, original);

    // change an array element in the original
    original.arr[0] = 'xxxxxxx';

    // the duplicate should not be affected
    t.is(dupe.arr[0], 'one');
    t.end();
});

Can you add a param(value) which is equal undefined during assigning

now:
deepAssign({a: {b: 0}}, {a: {b: 1, c: 2}}, {a: {c: 3}}); //=> {a: {b: 1, c: 3}} deepAssign({a: {b: 0}}, {a: {b: 1, c: 2}}, {a: {c: 3, b: undefined}}); //=> {a: {b: 1, c: 3}}
if (b === ' ' || 0 || false)
deepAssign({a: {b: 0}}, {a: {b: 1, c: 2}}, {a: {c: 3, b: '' }});
//=> {a: {b: 1, c: 3}}
not
//=> {a: {b: '' , c: 3}}

we can add any param regard as undefined
Thank you!

Overwriting array properties.

Is this intended behavior?

deepAssign({a: [1]}, {a: []}) => Object {a: Array[1]}

Based on the behavior of Object.assign (this module is just a recursive version of it correct?), I would have assumed it should have returned Object {a: Array[0]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.