change onbeforeremove and make state inherit from prototype
This commit is contained in:
parent
e8f36e4e26
commit
1222a9a3ab
4 changed files with 41 additions and 76 deletions
|
|
@ -97,7 +97,9 @@ module.exports = function($window) {
|
|||
function createComponent(vnode, hooks, ns) {
|
||||
// For object literals since `Vnode()` always sets the `state` field.
|
||||
if (!vnode.state) vnode.state = {}
|
||||
assign(vnode.state, vnode.tag)
|
||||
var constructor = function() {}
|
||||
constructor.prototype = vnode.tag
|
||||
vnode.state = new constructor
|
||||
|
||||
var view = vnode.tag.view
|
||||
if (view.reentrantLock != null) return $emptyFragment
|
||||
|
|
@ -380,12 +382,18 @@ module.exports = function($window) {
|
|||
function removeNode(vnode, context) {
|
||||
var expected = 1, called = 0
|
||||
if (vnode.attrs && vnode.attrs.onbeforeremove) {
|
||||
expected++
|
||||
vnode.attrs.onbeforeremove.call(vnode.state, vnode, once(continuation))
|
||||
var result = vnode.attrs.onbeforeremove.call(vnode.state, vnode)
|
||||
if (result != null && typeof result.then === "function") {
|
||||
expected++
|
||||
result.then(continuation, continuation)
|
||||
}
|
||||
}
|
||||
if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) {
|
||||
expected++
|
||||
vnode.tag.onbeforeremove.call(vnode.state, vnode, once(continuation))
|
||||
var result = vnode.tag.onbeforeremove.call(vnode.state, vnode)
|
||||
if (result != null && typeof result.then === "function") {
|
||||
expected++
|
||||
result.then(continuation, continuation)
|
||||
}
|
||||
}
|
||||
continuation()
|
||||
function continuation() {
|
||||
|
|
@ -559,10 +567,6 @@ module.exports = function($window) {
|
|||
return false
|
||||
}
|
||||
|
||||
function assign(target, source) {
|
||||
Object.keys(source).forEach(function(k){target[k] = source[k]})
|
||||
}
|
||||
|
||||
function render(dom, vnodes) {
|
||||
if (!dom) throw new Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.")
|
||||
var hooks = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue