question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should not create a new object if the values are the same

See original GitHub issue

I’m not sure if this is a bug or if I’m misunderstanding how this is supposed to work.

I assumed in the following example one and two would be the same object.

const obj = { foo: 0 };
const one = immutable(obj).set('foo', 'bar').value();
// { foo: 'bar' };
const two = immutable(one).set('foo', 'bar').value();
// { foo: 'bar' };
one === two
// false

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mariocasciarocommented, Oct 27, 2017

Thanks for the more detailed description. I get it now and it makes sense. We’ll track this as an enhancement as it’s going to change the current behaviour of a few methods. Thanks for reporting Luke.

0reactions
Prinzhorncommented, Jun 28, 2018

Was looking through the code and came to the conclusion that it is non-trivial at least for someone not comfortable with the code base. The problem is that the code works top-down and clones all objects along the path, but only at the very end inside changeCallback do we know if that was actually needed. At this point we could return the original thing, but still wasted time on all the cloning.

So how do we peek at the bottom to see if it would be a noop without duplicating most of the walking-logic? Or how do we delay/schedule the cloning until that point?

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How to avoid creating objects with same values?
Your current code well prevents different objects with same value from being created, but you can't stop an object from having two references. ......
Read more >
Creating Objects
When you create an object, you are creating an instance of a class, therefore "instantiating" a class. The new operator requires a single,...
Read more >
Objects - Definition & Usage - AutoHotkey
When an object reference is compared with some other value using = , == , != or <> , they are considered equal...
Read more >
Creating Objects - Learning the Java Language
Simply declaring a reference variable does not create an object. For that, you need to use the new operator, as described in the...
Read more >
Create Duplicate Object (CRTDUPOBJ) - IBM
It does not create an exact duplicate of files. The new object must be renamed if it is created in the library that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found