Comments (8)
I think if the condition on the next line is true, the function can still return true.
from nanomorph.
Ordering of the if
s are pretty important. That's why. So, no, it's not useless.
from nanomorph.
Consider this:
function same(a,b)
is called for a
and b
of Element type so effectively you get this:
function same (a, b) {
...
if (a.tagName !== b.tagName) return false; // either false
// if (a.type === TEXT_NODE) return a.nodeValue === b.nodeValue - dead statement if Elements
return false; // or false again
}
If a and b are Node's then a.tagName
is always undefined
thus that part looks as this
function same (a, b) {
...
// if (a.tagName !== b.tagName) return false; - dead statment if Nodes
if (a.type === TEXT_NODE) return a.nodeValue === b.nodeValue;
return false;
}
from nanomorph.
Even if this makes sense, still. The thing is that we don't know what a
and b
are at the point where we call the same()
. In one case it can be Element, in another, it can be Node. It's not completely useless or just sitting there, never used. I'm pretty sure it is covered when you run the coverage.
There are tons of tests. I also had reimplemented it (in demo-minmorph
) a dozen of times just out of curiosity.
from nanomorph.
Try this:
<html>
<head>
<title>Test</title>
</head>
<body>
<div>1</div>
<div>2</div>
</body>
<script type="text/javascript">
function same (a, b) {
if (a.id) return a.id === b.id;
if (a.isSameNode) return a.isSameNode(b);
if (a.tagName !== b.tagName) return false;
if (a.type === TEXT_NODE) return a.nodeValue === b.nodeValue;
return false;
}
var divs = document.body.getElementsByTagName("div");
console.log( same(divs[0],divs[1]) );
</script>
</html>
You will see false
in console. But I think true
is expected there, right?
from nanomorph.
But I think
true
is expected there, right?
Mmm, nope. Why it would be? It goes to the a.nodeValue === b.nodeValue
which should return false
, because it's 1 === 2
.
I'll say that again, same
is called recursively anyway, so 1) we don't know what's what in a given point in time and 2) it makes sense to have exactly these checks.
from nanomorph.
Mmm, nope. Why it would be?
Then if (a.tagName !== b.tagName) return false;
is useless.
QED.
from nanomorph.
Omg, in this exact case, yes of course. Remove it and run the tests, and you will see that we need it.
Even if we remove it or put it in separate function... We still need to have this check anyway. That's why it is there in the same
.
I'm done here.
from nanomorph.
Related Issues (20)
- SVG use does not repaint in firefox upon second update HOT 3
- Add TypeScript typings?
- Replace events.js to be more interop HOT 4
- Is this project dead? HOT 6
- Comments are un-commented HOT 4
- patching stateful DOM (input, textarea, form fields) HOT 1
- Recommended way to cache <img> elements
- Range element min + max attributes must come before value attribute
- Interview partners for research about communication in GitHub projects wanted
- [question] the list of events HOT 6
- can't set 'onchange' event in select tag HOT 5
- implement Meyers diffing algorithm HOT 31
- Input focus lost when sibling is added to parent node. HOT 1
- Clean up the test suite HOT 1
- Event Failures
- benchmark HOT 4
- questions before switching from morphdom HOT 1
- usage without require/module manager HOT 3
- Export `updateChildren()` or `childrenOnly` option HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanomorph.