#555 don't cache controller if redraw strategy is all

This commit is contained in:
Leo Horie 2015-04-14 21:38:21 -04:00
parent a7052510d6
commit ce883b4089
2 changed files with 43 additions and 1 deletions

View file

@ -240,7 +240,7 @@ var m = (function app(window, undefined) {
var controllerConstructors = [], controllers = []
while (data.view) {
var controllerConstructor = (data.controller || {}).$original || data.controller || function() {}
var controllerIndex = cached.controllerConstructors ? cached.controllerConstructors.indexOf(controllerConstructor) : -1
var controllerIndex = m.redraw.strategy() == "diff" && cached.controllerConstructors ? cached.controllerConstructors.indexOf(controllerConstructor) : -1
var controller = controllerIndex > -1 ? cached.controllers[controllerIndex] : new (data.controller || function() {})
var key = data && data.attrs && data.attrs.key
data = pendingRequests == 0 || cached ? data.view(controller) : {tag: "placeholder"}

View file

@ -1033,6 +1033,48 @@ function testMithril(mock) {
return !unloaded && found.id === "a"
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/555
var root = mock.document.createElement("div")
var MyComponent = {
controller: function(args) {
this.name = args.name;
},
view: function(ctrl) {
return m('div', ctrl.name);
}
}
var FooPage = {
view: function() {
return m('div', [
m('a[href=/]', {config: m.route}, 'foo'),
m('a[href=/bar]', {config: m.route}, 'bar'),
m.component(MyComponent, {name: 'Jane'})
]);
}
};
var BarPage = {
view: function() {
return m('div', [
m('a[href=/]', {config: m.route}, 'foo'),
m('a[href=/bar]', {config: m.route}, 'bar'),
m.component(MyComponent, {name: 'Bob'})
]);
}
};
m.route(root, '/', {
'/': FooPage,
'/bar': BarPage
})
mock.requestAnimationFrame.$resolve()
m.route("/bar")
mock.requestAnimationFrame.$resolve()
return root.childNodes[0].childNodes[2].childNodes[0].nodeValue == "Bob"
})
m.redraw.strategy(undefined) //teardown for m.mount tests
//m.withAttr