Make errors and their messages more accurate and helpful (#2536)

Also, I normalized them to all be sentences for consistency, and I moved
the reentrancy check from `m.mount` to `m.render` to be a little more
helpful. The router change during mounting is inconsequential and only
to avoid the new modified error, and the change to the update loop is to
send the original error if an error occurred while initializing the
default route. (This is all around more useful anyways.)

And while I was at it, I fixed an obscure bug with sync redraws.
This commit is contained in:
Isiah Meadows 2019-09-30 16:08:04 -04:00 committed by GitHub
parent 475747800a
commit b98ab29efd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 310 additions and 54 deletions

View file

@ -329,4 +329,65 @@ o.spec("render", function() {
render(root.childNodes[0], [{tag: "g"}])
o(root.childNodes[0].childNodes[0].namespaceURI).equals("http://www.w3.org/2000/svg")
})
o("does not allow reentrant invocations", function() {
var thrown = []
function A() {
var updated = false
try {render(root, {tag: A})} catch (e) {thrown.push("construct")}
return {
oninit: function() {
try {render(root, {tag: A})} catch (e) {thrown.push("oninit")}
},
oncreate: function() {
try {render(root, {tag: A})} catch (e) {thrown.push("oncreate")}
},
onbeforeupdate: function() {
try {render(root, {tag: A})} catch (e) {thrown.push("onbeforeupdate")}
},
onupdate: function() {
if (updated) return
updated = true
try {render(root, {tag: A})} catch (e) {thrown.push("onupdate")}
},
onbeforeremove: function() {
try {render(root, {tag: A})} catch (e) {thrown.push("onbeforeremove")}
},
onremove: function() {
try {render(root, {tag: A})} catch (e) {thrown.push("onremove")}
},
view: function() {
try {render(root, {tag: A})} catch (e) {thrown.push("view")}
},
}
}
render(root, {tag: A})
o(thrown).deepEquals([
"construct",
"oninit",
"view",
"oncreate",
])
render(root, {tag: A})
o(thrown).deepEquals([
"construct",
"oninit",
"view",
"oncreate",
"onbeforeupdate",
"view",
"onupdate",
])
render(root, [])
o(thrown).deepEquals([
"construct",
"oninit",
"view",
"oncreate",
"onbeforeupdate",
"view",
"onupdate",
"onbeforeremove",
"onremove",
])
})
})