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.

For values returned from diff(), null === {}

See original GitHub issue

The code responsible for this is in vm.diff.cmp. And it is executed during redrawSync().

Small test:

// Dummy vm for testing:
var vm = domvm.createView({render: function() {}});
vm.config({diff: function() {return 0;}});

// The comparison function that compares successive values returned by diff()
// doesn't differentiate between null and {}:
console.log("null === {}:", vm.diff.cmp(vm, null, {}));      // => false
console.log("null === null:", vm.diff.cmp(vm, null, null));  // => false

// It is actually the same problem for any primitive value:
console.log("12 === 34:", vm.diff.cmp(vm, 12, 34));    // => false
console.log("12 === 12:", vm.diff.cmp(vm, 12, 12));    // => false

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:29 (27 by maintainers)

github_iconTop GitHub Comments

1reaction
jlgrallcommented, Nov 30, 2018

Well there is still a problem with eq(). For example:

eq({}, null);  // => true
eq({}, 1);  // => true

This may happen because if one time you compare the old value null and the new value {}, the next time {} will be your old value, so the situation might be reversed.

Here is a possible solution:

function eq2(o, n) {
    return o === n || (
        typeof o === typeof n && n !== null && (
            isArr(o) ? eqArr(o, n) :
            isPlainObj(o) ? eqObj(o, n) :
            false
        )
    );
}

The idea is that if o and n are not the same type, we return false. We need to take care of the special case where either o or n is null. But we can actually skip the o !== null because that will fallthrough the following tests and return false.

1reaction
leeoniyacommented, Nov 27, 2018

Do you really want to exclude all objects that are not plain

kinda. for example, things like new Date and new Promise dont produce objects that are easily discernable without explicit checks, yet dont make sense to pass through cmpObj. also, cmpObj would iterate an instance’s public methods, etc.

worst case for this “breaking” change is a perf regression, so i’m not too concerned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are the error exit values for diff? - bash - Stack Overflow
It depends on your diff command. Mine (GNU diffutils 3.0) says: An exit status of 0 means no differences were found, 1 means...
Read more >
4 Ways to Replace NULL with a Different Value in MySQL
The IFNULL() function allows you to provide two arguments. The first argument is returned only if it is not NULL. If it is...
Read more >
sql server - Return NULL when distinct values else return value
I would like to find when two users have collected different surnames for the same name. The output I'm trying to get is:...
Read more >
null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >
Working with SQL NULL values - SQLShack
In the following query, the COALESCE() function returns the SQLShack.com because it is the first non-null value in the list.
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