#555 don't cache controller if redraw strategy is all
This commit is contained in:
parent
a7052510d6
commit
ce883b4089
2 changed files with 43 additions and 1 deletions
|
|
@ -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"}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue