diff --git a/archive/v0.1.9/change-log.html b/archive/v0.1.9/change-log.html
index 73846f27..3af53572 100644
--- a/archive/v0.1.9/change-log.html
+++ b/archive/v0.1.9/change-log.html
@@ -69,6 +69,11 @@
m.prop is now JSON-serializable #54
added extract option to m.request to allow access to response metadata #53
+Bug Fixes:
+
+- Fixed node index displacement by null/undefined nodes #56
+- Fixed mock's insertBefore and appendChild when dealing w/ reattachments
+
Breaking changes:
- changing an id in a virtual element now recreates the element, instead of recycling it #55
diff --git a/archive/v0.1.9/mithril-tests.js b/archive/v0.1.9/mithril-tests.js
index e156708e..265fc8e6 100644
--- a/archive/v0.1.9/mithril-tests.js
+++ b/archive/v0.1.9/mithril-tests.js
@@ -48,18 +48,18 @@ Mithril = m = new function app(window) {
if (dataType == "[object Array]") {
var nodes = [], intact = cached.length === data.length, subArrayCount = 0
- for (var i = 0; i < data.length; i++) {
- var item = build(parent, data[i], cached[i], shouldReattach, index + subArrayCount || subArrayCount, namespace)
+ for (var i = 0, cacheCount = 0; i < data.length; i++) {
+ var item = build(parent, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, namespace)
if (item === undefined) continue
if (!item.nodes.intact) intact = false
subArrayCount += item instanceof Array ? item.length : 1
- cached[i] = item
+ cached[cacheCount++] = item
}
if (!intact) {
for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node)
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parent.appendChild(node)
- cached.length = data.length
+ if (data.length < cached.length) cached.length = data.length
cached.nodes = nodes
}
}
@@ -498,9 +498,12 @@ mock.window = new function() {
replaceChild: window.document.replaceChild,
insertBefore: function(node, reference) {
node.parentNode = this
- var index = this.childNodes.indexOf(reference)
- if (index < 0) this.childNodes.push(node)
- else this.childNodes.splice(index, 0, node)
+ var referenceIndex = this.childNodes.indexOf(reference)
+ if (referenceIndex < 0) this.childNodes.push(node)
+ else {
+ var index = this.childNodes.indexOf(node)
+ this.childNodes.splice(referenceIndex, index < 0 ? 0 : 1, node)
+ }
},
insertAdjacentHTML: function(position, html) {
//todo: accept markup
@@ -540,6 +543,8 @@ mock.window = new function() {
oldChild.parentNode = null
}
window.document.appendChild = function(child) {
+ var index = this.childNodes.indexOf(child)
+ if (index > -1) this.childNodes.splice(index, 1)
this.childNodes.push(child)
child.parentNode = this
}
@@ -899,6 +904,14 @@ function testMithril(mock) {
var elementAfter = root.childNodes[0]
return elementBefore !== elementAfter
})
+ test(function() {
+ //https://github.com/lhorie/mithril.js/issues/56
+ var root = mock.document.createElement("div")
+ m.render(root, [null, "foo"])
+ m.render(root, ["bar"])
+ console.log(root.childNodes)
+ return root.childNodes.length == 1
+ })
//end m.render
//m.redraw
diff --git a/archive/v0.1.9/mithril.js b/archive/v0.1.9/mithril.js
index d9b1cce7..c4061228 100644
--- a/archive/v0.1.9/mithril.js
+++ b/archive/v0.1.9/mithril.js
@@ -48,18 +48,18 @@ Mithril = m = new function app(window) {
if (dataType == "[object Array]") {
var nodes = [], intact = cached.length === data.length, subArrayCount = 0
- for (var i = 0; i < data.length; i++) {
- var item = build(parent, data[i], cached[i], shouldReattach, index + subArrayCount || subArrayCount, namespace)
+ for (var i = 0, cacheCount = 0; i < data.length; i++) {
+ var item = build(parent, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, namespace)
if (item === undefined) continue
if (!item.nodes.intact) intact = false
subArrayCount += item instanceof Array ? item.length : 1
- cached[i] = item
+ cached[cacheCount++] = item
}
if (!intact) {
for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node)
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parent.appendChild(node)
- cached.length = data.length
+ if (data.length < cached.length) cached.length = data.length
cached.nodes = nodes
}
}
diff --git a/archive/v0.1.9/mithril.min.js b/archive/v0.1.9/mithril.min.js
index 6575620f..51ad4e68 100644
--- a/archive/v0.1.9/mithril.min.js
+++ b/archive/v0.1.9/mithril.min.js
@@ -4,5 +4,5 @@ http://github.com/lhorie/mithril.js
(c) Leo Horie
License: MIT
*/
-Mithril=m=new function(a){function b(){var a=arguments,b="[object Object]"==u.call(a[1]),c=b?a[1]:{},d="class"in c?"class":"className",e=t[a[0]];if(void 0===e){t[a[0]]=e={tag:"div",attrs:{}};for(var f,h=[];f=v.exec(a[0]);)if(""==f[1])e.tag=f[2];else if("#"==f[1])e.attrs.id=f[2];else if("."==f[1])h.push(f[2]);else if("["==f[3][0]){var i=w.exec(f[3]);e.attrs[i[1]]=i[3]||!0}h.length>0&&(e.attrs[d]=h.join(" "))}e=g(e),e.attrs=g(e.attrs),e.children=b?a[2]:a[1];for(var j in c)e.attrs[j]=j==d?(e.attrs[j]||"")+" "+c[j]:c[j];return e}function c(b,g,h,i,j,k){if(null===g||void 0===g)return void(h&&e(h.nodes));if("retain"!==g.subtree){var l=u.call(h),m=u.call(g);if(l!=m&&(null!==h&&void 0!==h&&e(h.nodes),h=new g.constructor,h.nodes=[]),"[object Array]"==m){for(var n=[],o=h.length===g.length,p=0,q=0;q-1?new g.constructor(g):g,h.nodes=[s];else if(h.valueOf()!==g.valueOf()||i===!0){if(g.$trusted){var v=h.nodes[0],n=[v];if(v){for(;v=v.nextSibling;)n.push(v);e(n),s=f(b,j,g)}else b.innerHTML=g}else s=h.nodes[0],b.insertBefore(s,b.childNodes[j]||null),s.nodeValue=g;h=new g.constructor(g),h.nodes=[s]}else h.nodes.intact=!0}return h}}function d(b,c,d,e){for(var f in c){var g=c[f],i=d[f];if(!(f in d)||i!==g||b===a.document.activeElement){if(d[f]=g,"config"===f)continue;if("function"==typeof g&&0==f.indexOf("on"))b[f]=h(g,b);else if("style"===f)for(var j in g)(void 0===i||i[j]!==g[j])&&(b.style[j]=g[j]);else void 0!==e?"href"===f?b.setAttributeNS("http://www.w3.org/1999/xlink","href",g):"className"===f?b.setAttribute("class",g):b.setAttribute(f,g):f in b?b[f]=g:b.setAttribute(f,g)}}return d}function e(a){for(var b=0;b16)b.redraw();else{var c=a.cancelAnimationFrame||a.clearTimeout,d=a.requestAnimationFrame||a.setTimeout;c(F),F=d(b.redraw,0)}}function j(a,c,d){K={};for(var e in c){if(e==d)return!void b.module(a,c[e]);var f=new RegExp("^"+e.replace(/:[^\/]+/g,"([^\\/]+)")+"$");if(f.test(d))return!void d.replace(f,function(){for(var d=e.match(/:[^\/]+/g),f=[].slice.call(arguments,1,-2),g=0;g0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+o(b):a.data=c(b)),a}function q(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;de?y.push(b)-1:e,g=b==a.document||b==a.document.documentElement?x:b;z[f]=c(g,d,z[f],!1,0)},b.trust=function(a){return a=new String(a),a.$trusted=!0,a};var A=[],B=[],C=[],D=0,E=0,F=0;b.module=function(a,c){b.startComputation();var d=A.indexOf(a);0>d&&(d=A.length),A[d]=a,B[d]=c,C[d]=new c.controller,b.endComputation()},b.redraw=function(){for(var a=0;a0&&(e.attrs[d]=h.join(" "))}e=g(e),e.attrs=g(e.attrs),e.children=b?a[2]:a[1];for(var j in c)e.attrs[j]=j==d?(e.attrs[j]||"")+" "+c[j]:c[j];return e}function c(b,g,h,i,j,k){if(null===g||void 0===g)return void(h&&e(h.nodes));if("retain"!==g.subtree){var l=u.call(h),m=u.call(g);if(l!=m&&(null!==h&&void 0!==h&&e(h.nodes),h=new g.constructor,h.nodes=[]),"[object Array]"==m){for(var n=[],o=h.length===g.length,p=0,q=0,r=0;q-1?new g.constructor(g):g,h.nodes=[t];else if(h.valueOf()!==g.valueOf()||i===!0){if(g.$trusted){var w=h.nodes[0],n=[w];if(w){for(;w=w.nextSibling;)n.push(w);e(n),t=f(b,j,g)}else b.innerHTML=g}else t=h.nodes[0],b.insertBefore(t,b.childNodes[j]||null),t.nodeValue=g;h=new g.constructor(g),h.nodes=[t]}else h.nodes.intact=!0}return h}}function d(b,c,d,e){for(var f in c){var g=c[f],i=d[f];if(!(f in d)||i!==g||b===a.document.activeElement){if(d[f]=g,"config"===f)continue;if("function"==typeof g&&0==f.indexOf("on"))b[f]=h(g,b);else if("style"===f)for(var j in g)(void 0===i||i[j]!==g[j])&&(b.style[j]=g[j]);else void 0!==e?"href"===f?b.setAttributeNS("http://www.w3.org/1999/xlink","href",g):"className"===f?b.setAttribute("class",g):b.setAttribute(f,g):f in b?b[f]=g:b.setAttribute(f,g)}}return d}function e(a){for(var b=0;b16)b.redraw();else{var c=a.cancelAnimationFrame||a.clearTimeout,d=a.requestAnimationFrame||a.setTimeout;c(F),F=d(b.redraw,0)}}function j(a,c,d){K={};for(var e in c){if(e==d)return!void b.module(a,c[e]);var f=new RegExp("^"+e.replace(/:[^\/]+/g,"([^\\/]+)")+"$");if(f.test(d))return!void d.replace(f,function(){for(var d=e.match(/:[^\/]+/g),f=[].slice.call(arguments,1,-2),g=0;g0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+o(b):a.data=c(b)),a}function q(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;de?y.push(b)-1:e,g=b==a.document||b==a.document.documentElement?x:b;z[f]=c(g,d,z[f],!1,0)},b.trust=function(a){return a=new String(a),a.$trusted=!0,a};var A=[],B=[],C=[],D=0,E=0,F=0;b.module=function(a,c){b.startComputation();var d=A.indexOf(a);0>d&&(d=A.length),A[d]=a,B[d]=c,C[d]=new c.controller,b.endComputation()},b.redraw=function(){for(var a=0;a -1) this.childNodes.splice(index, 1)
this.childNodes.push(child)
child.parentNode = this
}