Reverse hook order for all but onbeforeupdate (#2297)
- Drive-by: `onbeforeupdate` prevents subtree redraw if *either* hook returns `false`, not *both*.
This commit is contained in:
parent
c33621cd52
commit
a8473e63c9
4 changed files with 45 additions and 33 deletions
|
|
@ -699,13 +699,23 @@ o.spec("component", function() {
|
|||
"onupdate", "onbeforeremove", "onremove"
|
||||
]
|
||||
hooks.forEach(function(hook) {
|
||||
// the `attrs` hooks are called before the component ones
|
||||
attrs[hook] = o.spy(function() {
|
||||
o(attrs[hook].callCount).equals(methods[hook].callCount + 1)
|
||||
})
|
||||
methods[hook] = o.spy(function() {
|
||||
o(attrs[hook].callCount).equals(methods[hook].callCount)
|
||||
})
|
||||
if (hook === "onbeforeupdate") {
|
||||
// the component's `onbeforeupdate` is called after the `attrs`' one
|
||||
attrs[hook] = o.spy(function() {
|
||||
o(attrs[hook].callCount).equals(methods[hook].callCount + 1)(hook)
|
||||
})
|
||||
methods[hook] = o.spy(function() {
|
||||
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
||||
})
|
||||
} else {
|
||||
// the other component hooks are called before the `attrs` ones
|
||||
methods[hook] = o.spy(function() {
|
||||
o(attrs[hook].callCount).equals(methods[hook].callCount - 1)(hook)
|
||||
})
|
||||
attrs[hook] = o.spy(function() {
|
||||
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
var component = createComponent(methods)
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ o.spec("onbeforeupdate", function() {
|
|||
o(root.firstChild.attributes["id"].value).equals("b")
|
||||
})
|
||||
|
||||
o("does not prevent update if returning false in component but true in vnode", function() {
|
||||
o("prevents update if returning false in component but true in vnode", function() {
|
||||
var component = createComponent({
|
||||
onbeforeupdate: function() {return false},
|
||||
view: function(vnode) {
|
||||
|
|
@ -199,10 +199,10 @@ o.spec("onbeforeupdate", function() {
|
|||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(root.firstChild.attributes["id"].value).equals("b")
|
||||
o(root.firstChild.attributes["id"].value).equals("a")
|
||||
})
|
||||
|
||||
o("does not prevent update if returning true in component but false in vnode", function() {
|
||||
o("prevents update if returning true in component but false in vnode", function() {
|
||||
var component = createComponent({
|
||||
onbeforeupdate: function() {return true},
|
||||
view: function(vnode) {
|
||||
|
|
@ -215,7 +215,7 @@ o.spec("onbeforeupdate", function() {
|
|||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(root.firstChild.attributes["id"].value).equals("b")
|
||||
o(root.firstChild.attributes["id"].value).equals("a")
|
||||
})
|
||||
|
||||
o("does not prevent update if returning true from component", function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue