fix(lifecycle): continue to handle data
This commit is contained in:
parent
d9b487e67b
commit
955d3d5988
2 changed files with 4 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ const install = function (hook, vm) {
|
|||
})
|
||||
}
|
||||
|
||||
window.$docsify.plugins = [].concat(install, window.$docsify.plugins)
|
||||
$docsify.plugins = [].concat(install, $docsify.plugins)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue