Skip to content
This repository has been archived by the owner on Dec 19, 2017. It is now read-only.

Commit

Permalink
fix bug #64
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyWebb committed Jun 9, 2016
1 parent 0894ce1 commit 4d9e778
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,32 @@ export default class Context {
}

runBeforeNavigateCallbacks() {
const ctx = this
let ctx = this
let callbacks = []

return run()
while (ctx) {
callbacks = ctx._beforeNavigateCallbacks.concat(callbacks)
ctx = ctx.$child
}

return run(callbacks)

function run(i = 0) {
function run(callbacks) {
return new Promise((resolve) => {
if (i === ctx._beforeNavigateCallbacks.length) {
if (callbacks.length === 0) {
return resolve(true)
}
const cb = ctx._beforeNavigateCallbacks[i]
const cb = callbacks.shift()
const recursiveResolve = (shouldUpdate = true) => shouldUpdate
? run(++i).then(resolve)
? run(callbacks).then(resolve)
: resolve(false)

if (cb.length === 1) {
cb(recursiveResolve)
} else {
const v = cb()
if (isUndefined(v) || typeof v.then !== 'function') {
resolve(v !== false)
recursiveResolve(v)
} else {
v.then(recursiveResolve)
}
Expand Down

0 comments on commit 4d9e778

Please sign in to comment.