allow string keys
This commit is contained in:
parent
5003c0ac23
commit
3de5cb8aaf
2 changed files with 37 additions and 3 deletions
|
|
@ -442,11 +442,10 @@ var m = (function app(window, undefined) {
|
||||||
|
|
||||||
function checkView(data, view, cached, cachedControllers, controllers, views) {
|
function checkView(data, view, cached, cachedControllers, controllers, views) {
|
||||||
var controller = getController(cached.views, view, cachedControllers, data.controller);
|
var controller = getController(cached.views, view, cachedControllers, data.controller);
|
||||||
//Faster to coerce to number and check for NaN
|
var key = data && data.attrs && data.attrs.key;
|
||||||
var key = +(data && data.attrs && data.attrs.key);
|
|
||||||
data = pendingRequests === 0 || forcing || cachedControllers && cachedControllers.indexOf(controller) > -1 ? data.view(controller) : {tag: "placeholder"};
|
data = pendingRequests === 0 || forcing || cachedControllers && cachedControllers.indexOf(controller) > -1 ? data.view(controller) : {tag: "placeholder"};
|
||||||
if (data.subtree === "retain") return data;
|
if (data.subtree === "retain") return data;
|
||||||
if (key === key) (data.attrs = data.attrs || {}).key = key;
|
(data.attrs = data.attrs || {}).key = key;
|
||||||
updateLists(views, controllers, view, controller);
|
updateLists(views, controllers, view, controller);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -269,6 +269,41 @@ function testMithril(mock) {
|
||||||
|
|
||||||
return firstBefore === firstAfter
|
return firstBefore === firstAfter
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
//string keys in components should work
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
var list = [1, 2, 3]
|
||||||
|
var component = {
|
||||||
|
controller: function() {},
|
||||||
|
view: function() {
|
||||||
|
return list.map(function(i) {
|
||||||
|
return m.component(sub, {key: "key" + i})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sub = {
|
||||||
|
controller: function() {},
|
||||||
|
view: function() {
|
||||||
|
return m("div")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.mount(root, component)
|
||||||
|
|
||||||
|
var firstBefore = root.childNodes[0]
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
list.reverse()
|
||||||
|
m.redraw(true)
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
var firstAfter = root.childNodes[2]
|
||||||
|
|
||||||
|
return firstBefore === firstAfter
|
||||||
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
//keys in subcomponents should work
|
//keys in subcomponents should work
|
||||||
mock.requestAnimationFrame.$resolve()
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue