revert workaround for #29 in favor of key-based solution
This commit is contained in:
parent
aa23da4fd1
commit
d32dd4adf5
2 changed files with 1 additions and 26 deletions
|
|
@ -275,8 +275,7 @@ Mithril = m = new function app(window, undefined) {
|
||||||
for (var attrName in dataAttrs) {
|
for (var attrName in dataAttrs) {
|
||||||
var dataAttr = dataAttrs[attrName]
|
var dataAttr = dataAttrs[attrName]
|
||||||
var cachedAttr = cachedAttrs[attrName]
|
var cachedAttr = cachedAttrs[attrName]
|
||||||
//see #29 for the reason behind `activeElement` usage
|
if (!(attrName in cachedAttrs) || (cachedAttr !== dataAttr)) {
|
||||||
if (!(attrName in cachedAttrs) || (cachedAttr !== dataAttr) || node === window.document.activeElement) {
|
|
||||||
cachedAttrs[attrName] = dataAttr
|
cachedAttrs[attrName] = dataAttr
|
||||||
try {
|
try {
|
||||||
//`config` isn't a real attributes, so ignore it
|
//`config` isn't a real attributes, so ignore it
|
||||||
|
|
@ -300,10 +299,6 @@ Mithril = m = new function app(window, undefined) {
|
||||||
else if (attrName === "className") node.setAttribute("class", dataAttr)
|
else if (attrName === "className") node.setAttribute("class", dataAttr)
|
||||||
else node.setAttribute(attrName, dataAttr)
|
else node.setAttribute(attrName, dataAttr)
|
||||||
}
|
}
|
||||||
//part of fix for #29
|
|
||||||
else if (attrName === "value" && tag === "input") {
|
|
||||||
if (node.value !== dataAttr) node.value = dataAttr
|
|
||||||
}
|
|
||||||
//handle cases that are properties (but ignore cases where we should use setAttribute instead)
|
//handle cases that are properties (but ignore cases where we should use setAttribute instead)
|
||||||
//- list and form are typically used as strings, but are DOM element references in js
|
//- list and form are typically used as strings, but are DOM element references in js
|
||||||
//- when using CSS selectors (e.g. `m("[style='']")`), style is used as a string, but it's an object in js
|
//- when using CSS selectors (e.g. `m("[style='']")`), style is used as a string, but it's an object in js
|
||||||
|
|
|
||||||
|
|
@ -167,26 +167,6 @@ function testMithril(mock) {
|
||||||
m.render(root, m("a", {config: m.route}, "test"))
|
m.render(root, m("a", {config: m.route}, "test"))
|
||||||
return root.childNodes[0].childNodes[0].nodeValue === "test"
|
return root.childNodes[0].childNodes[0].nodeValue === "test"
|
||||||
})
|
})
|
||||||
test(function() {
|
|
||||||
//https://github.com/lhorie/mithril.js/issues/29
|
|
||||||
var root = mock.document.createElement("div")
|
|
||||||
var list = [false, false]
|
|
||||||
m.render(root, list.reverse().map(function(flag, index) {
|
|
||||||
return m("input[type=checkbox]", {onclick: m.withAttr("checked", function(value) {list[index] = value}), checked: flag})
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.document.activeElement = root.childNodes[0]
|
|
||||||
root.childNodes[0].checked = true
|
|
||||||
root.childNodes[0].onclick({currentTarget: {checked: true}})
|
|
||||||
|
|
||||||
m.render(root, list.reverse().map(function(flag, index) {
|
|
||||||
return m("input[type=checkbox]", {onclick: m.withAttr("checked", function(value) {list[index] = value}), checked: flag})
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.document.activeElement = null
|
|
||||||
|
|
||||||
return root.childNodes[0].checked === false && root.childNodes[1].checked === true
|
|
||||||
})
|
|
||||||
test(function() {
|
test(function() {
|
||||||
//https://github.com/lhorie/mithril.js/issues/44 (1)
|
//https://github.com/lhorie/mithril.js/issues/44 (1)
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue