Skip to content

Commit

Permalink
Use data-bel as element identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Mar 5, 2016
1 parent 89d1f09 commit 5cbdfde
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,23 @@ var id = 0

module.exports = function bel () {
var el = hx.apply(this, arguments)
if (!el.id) {
el.id = 'bel-' + id
if (el.dataset && !el.dataset.bel) {
el.dataset.bel = id
id += 1
}
el.update = function (newel) {
if (typeof newel === 'function') {
newel = newel()
}
// TODO: Someday eliminate the need for this
// We need to look up the actual element in the DOM because a parent element
// could have called .update() and replaced the child node
el = document.getElementById(el.id)
newel.id = el.id
morphdom(el, newel)
newel.dataset.bel = el.dataset.bel
return morphdom(el, newel, {
getNodeKey: function (el) {
if (el.dataset && el.dataset.bel) {
return el.dataset.bel
}
return el.id
}
})
}
return el
}

0 comments on commit 5cbdfde

Please sign in to comment.