Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert on-load attribute special case behaviour #65

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
var assert = require('assert')
var morph = require('./lib/morph')
var rootLabelRegex = /^data-onloadid/

var ELEMENT_NODE = 1

module.exports = nanomorph

Expand All @@ -22,8 +19,6 @@ module.exports = nanomorph
function nanomorph (oldTree, newTree) {
assert.equal(typeof oldTree, 'object', 'nanomorph: oldTree should be an object')
assert.equal(typeof newTree, 'object', 'nanomorph: newTree should be an object')

persistStatefulRoot(newTree, oldTree)
var tree = walk(newTree, oldTree)
return tree
}
Expand Down Expand Up @@ -87,17 +82,3 @@ function updateChildren (newNode, oldNode) {
newIndex = newStartIndex
}
}

function persistStatefulRoot (newNode, oldNode) {
if (!newNode || !oldNode || oldNode.nodeType !== ELEMENT_NODE || newNode.nodeType !== ELEMENT_NODE) return
var oldAttrs = oldNode.attributes
var attr, name
for (var i = 0, len = oldAttrs.length; i < len; i++) {
attr = oldAttrs[i]
name = attr.name
if (rootLabelRegex.test(name)) {
newNode.setAttribute(name, attr.value)
break
}
}
}
23 changes: 0 additions & 23 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,6 @@ function abstractMorph (morph) {
})
}

tape('should skip over data-onload attributes at root', function (t) {
var a = html`
<section data-onloadidzina="o0">
<input data-onloadidzina="o1">
</section>
`
var b = html`
<section>
<input autofocus="autofocus" value="" class="f6 normal">
<button class="bg-light-gray white ttu">save</button>
</section>
`
var c = html`
<section data-onloadidzina="o0">
<input autofocus="autofocus" value="" class="f6 normal">
<button class="bg-light-gray white ttu">save</button>
</section>
`
var d = nanomorph(a, b)
t.ok(c.isEqualNode(d), 'is equal')
t.end()
})

tape('use id as a key hint', function (t) {
t.test('append an element', function (t) {
var a = html`<ul>
Expand Down