fix(lifecycle): continue to handle data

This commit is contained in:
qingwei.li 2017-05-31 21:20:09 +08:00
commit 955d3d5988
No known key found for this signature in database
GPG key ID: B6DDC2F7AE80B2F4
2 changed files with 4 additions and 5 deletions

View file

@ -19,23 +19,22 @@ export function initLifecycle (vm) {
}
export function callHook (vm, hook, data, next = noop) {
let newData = data
const queue = vm._hooks[hook]
const step = function (index) {
const hook = queue[index]
if (index >= queue.length) {
next(newData)
next(data)
} else {
if (typeof hook === 'function') {
if (hook.length === 2) {
hook(data, result => {
newData = result
data = result
step(index + 1)
})
} else {
const result = hook(data)
newData = result !== undefined ? result : newData
data = result !== undefined ? result : data
step(index + 1)
}
} else {

View file

@ -10,4 +10,4 @@ const install = function (hook, vm) {
})
}
window.$docsify.plugins = [].concat(install, window.$docsify.plugins)
$docsify.plugins = [].concat(install, $docsify.plugins)