From 5cbdfde4fd9f9161183c421619c852141c54e530 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Fri, 4 Mar 2016 20:28:46 -0800 Subject: [PATCH] Use data-bel as element identifier --- index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 8b91eec..0d4c671 100644 --- a/index.js +++ b/index.js @@ -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 }