don't redraw component before async service finishes
This commit is contained in:
parent
cc8cac358a
commit
cf1f316bee
2 changed files with 102 additions and 5 deletions
|
|
@ -244,7 +244,7 @@ var m = (function app(window, undefined) {
|
||||||
var controllerIndex = m.redraw.strategy() == "diff" && 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 controller = controllerIndex > -1 ? cached.controllers[controllerIndex] : new (data.controller || function() {})
|
||||||
var key = data && data.attrs && data.attrs.key
|
var key = data && data.attrs && data.attrs.key
|
||||||
data = pendingRequests == 0 || cached ? data.view(controller) : {tag: "placeholder"}
|
data = pendingRequests == 0 || (cached && cached.controllers) ? data.view(controller) : {tag: "placeholder"}
|
||||||
if (key) {
|
if (key) {
|
||||||
if (!data.attrs) data.attrs = {}
|
if (!data.attrs) data.attrs = {}
|
||||||
data.attrs.key = key
|
data.attrs.key = key
|
||||||
|
|
|
||||||
|
|
@ -969,7 +969,7 @@ function testMithril(mock) {
|
||||||
test(function() {
|
test(function() {
|
||||||
//https://github.com/lhorie/mithril.js/issues/551
|
//https://github.com/lhorie/mithril.js/issues/551
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
var a = false, found = false, unloaded = false
|
var a = false, found = false, unloaded = false, redraws = 0
|
||||||
var Root = {
|
var Root = {
|
||||||
view: function() {
|
view: function() {
|
||||||
return Comp
|
return Comp
|
||||||
|
|
@ -977,6 +977,7 @@ function testMithril(mock) {
|
||||||
}
|
}
|
||||||
var Comp = {
|
var Comp = {
|
||||||
view: function() {
|
view: function() {
|
||||||
|
redraws++
|
||||||
return m("div", {config: Comp.config}, [
|
return m("div", {config: Comp.config}, [
|
||||||
m("div", {onclick: function() {
|
m("div", {onclick: function() {
|
||||||
a = !a
|
a = !a
|
||||||
|
|
@ -1000,12 +1001,12 @@ function testMithril(mock) {
|
||||||
|
|
||||||
mock.requestAnimationFrame.$resolve()
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
return !unloaded && found.id === "a"
|
return !unloaded && found.id === "a" && redraws == 3
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
//https://github.com/lhorie/mithril.js/issues/551
|
//https://github.com/lhorie/mithril.js/issues/551
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
var a = false, found = false, unloaded = false
|
var a = false, found = false, unloaded = false, redraws = 0
|
||||||
var Root = {
|
var Root = {
|
||||||
view: function() {
|
view: function() {
|
||||||
return Comp
|
return Comp
|
||||||
|
|
@ -1013,6 +1014,7 @@ function testMithril(mock) {
|
||||||
}
|
}
|
||||||
var Comp = {
|
var Comp = {
|
||||||
view: function() {
|
view: function() {
|
||||||
|
redraws++
|
||||||
return m("div", {config: Comp.config}, [
|
return m("div", {config: Comp.config}, [
|
||||||
m("div", {onclick: function() {
|
m("div", {onclick: function() {
|
||||||
a = !a
|
a = !a
|
||||||
|
|
@ -1037,7 +1039,26 @@ function testMithril(mock) {
|
||||||
|
|
||||||
mock.requestAnimationFrame.$resolve()
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
return !unloaded && found.id === "a"
|
return !unloaded && found.id === "a" && redraws == 2
|
||||||
|
})
|
||||||
|
test(function() {
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
var redraws = 0
|
||||||
|
var Root = {
|
||||||
|
view: function() {
|
||||||
|
redraws++
|
||||||
|
return m("div", {onclick: function() {m.redraw(true)}})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.mount(root, Root)
|
||||||
|
|
||||||
|
var target = root.childNodes[0]
|
||||||
|
target.onclick({currentTarget: target})
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
return redraws == 3
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
//https://github.com/lhorie/mithril.js/issues/555
|
//https://github.com/lhorie/mithril.js/issues/555
|
||||||
|
|
@ -1081,6 +1102,82 @@ function testMithril(mock) {
|
||||||
|
|
||||||
return root.childNodes[0].childNodes[2].childNodes[0].nodeValue == "Bob"
|
return root.childNodes[0].childNodes[2].childNodes[0].nodeValue == "Bob"
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
var redraws = 0, data
|
||||||
|
var Root = {
|
||||||
|
view: function() {
|
||||||
|
return Comp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var Comp = {
|
||||||
|
controller: function() {
|
||||||
|
this.foo = m.request({method: "GET", url: "/foo"})
|
||||||
|
},
|
||||||
|
view: function(ctrl) {
|
||||||
|
redraws++
|
||||||
|
data = ctrl.foo()
|
||||||
|
return m("div")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.mount(root, Root)
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
m.mount(root, null)
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
return redraws == 1 && data.url == "/foo"
|
||||||
|
})
|
||||||
|
test(function() {
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
var redraws1 = 0, redraws2 = 0
|
||||||
|
var Root = {
|
||||||
|
view: function() {
|
||||||
|
return m("div", [
|
||||||
|
Comp1,
|
||||||
|
Comp2
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var Comp1 = {
|
||||||
|
controller: function() {
|
||||||
|
this.foo = m.request({method: "GET", url: "/foo"})
|
||||||
|
},
|
||||||
|
view: function(ctrl) {
|
||||||
|
redraws1++
|
||||||
|
return m("div")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var Comp2 = {
|
||||||
|
controller: function() {
|
||||||
|
this.bar = m.request({method: "GET", url: "/bar"})
|
||||||
|
},
|
||||||
|
view: function(ctrl) {
|
||||||
|
redraws2++
|
||||||
|
return m("div")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.mount(root, Root)
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
m.mount(root, null)
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
return redraws1 == 1 && redraws2 == 1
|
||||||
|
})
|
||||||
m.redraw.strategy(undefined) //teardown for m.mount tests
|
m.redraw.strategy(undefined) //teardown for m.mount tests
|
||||||
|
|
||||||
//m.withAttr
|
//m.withAttr
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue