grapetreeCore.js
function loopThroughHandlers(lastFuture, n) {
            if(n < routes.length) {
                var route = routes[n].route
                var handler = route[handlerProperty]

                if(direction === -1) {
                    var originalIndexFromCurrentRoutes = currentRoutes.length - n - 1
                    var distance = routes.length - n        // divergenceDistance
                } else {
                    var originalIndexFromCurrentRoutes = routeVergenceIndex+n
                    var distance = undefined                // no more leafDistance: routes.length - n - 1    // leafDistance
                }

                return lastFuture.then(function() {
                    if(handler !== undefined) {
                        if(originalIndexFromCurrentRoutes > 0) {
                            var parentRoute = currentRoutes[originalIndexFromCurrentRoutes-1]
                            var lastValue = parentRoute.route.lastValue
                        }

                        var nextFuture = handler.call(route, lastValue, distance)
                        if(nextFuture !== undefined) {
                            nextFuture.then(function(value) {
                                route.lastValue = value
                            }) // no done because nextFuture's errors are handled elsewhere
                        }
                    }

                    if(nextFuture === undefined) {
                        nextFuture = Future(undefined)
                    }

                    return loopThroughHandlers(nextFuture, n+1)

                }).catch(function(e){
                    return handleError(currentRoutes, originalIndexFromCurrentRoutes, type, e, []).then(function() {
                        if(direction === 1) {
                            return Future(n + routeVergenceIndex)
                        } else { // -1 exit handlers
                            return loopThroughHandlers(Future(undefined), n+1)  // continue executing the parent exit handlers
                        }
                    })
                })
            } else {
                return lastFuture.then(function() {
                    return Future(n + routeVergenceIndex)
                }).catch(function(e) {
                    throw e // propagate the error not the value
                })
            }
        }
function loopThroughHandlers(lastFuture, n) {
            if(n < routes.length) {
                var route = routes[n].route
                var handler = route[handlerProperty]

                if(direction === -1) {
                    var originalIndexFromCurrentRoutes = currentRoutes.length - n - 1
                    var distance = routes.length - n        // divergenceDistance
                } else {
                    var originalIndexFromCurrentRoutes = routeVergenceIndex+n
                    var distance = undefined                // no more leafDistance: routes.length - n - 1    // leafDistance
                }

                return lastFuture.then(function() {
                    if(handler !== undefined) {
                        if(originalIndexFromCurrentRoutes > 0) {
                            var parentRoute = currentRoutes[originalIndexFromCurrentRoutes-1]
                            var lastValue = parentRoute.route.lastValue
                        }

                        var nextFuture = handler.call(route, lastValue, distance)
                        if(nextFuture !== undefined) {
                            nextFuture.then(function(value) {
                                route.lastValue = value
                            }) // no done because nextFuture's errors are handled elsewhere
                        }
                    }

                    if(nextFuture === undefined) {
                        nextFuture = Future(undefined)
                    }

                    return loopThroughHandlers(nextFuture, n+1)

                }).catch(function(e){
                    return handleError(currentRoutes, originalIndexFromCurrentRoutes, type, e, []).then(function() {
                        if(direction === 1) {
                            return Future(n + routeVergenceIndex)
                        } else { // -1 exit handlers
                            return loopThroughHandlers(Future(undefined), n+1)  // continue executing the parent exit handlers
                        }
                    })
                })
            } else {
                return lastFuture.then(function() {
                    return Future(n + routeVergenceIndex)
                }).catch(function(e) {
                    throw e // propagate the error not the value
                })
            }
        }
function loopThroughHandlers ( lastFuture , n ) { if ( n < routes . length ) { var route = routes [ n ] . route var handler = route [ handlerProperty ] if ( direction === - 1 ) { var originalIndexFromCurrentRoutes = currentRoutes . length - n - 1 var distance = routes . length - n // divergenceDistance } else { var originalIndexFromCurrentRoutes = routeVergenceIndex + n var distance = undefined // no more leafDistance: routes.length - n - 1    // leafDistance } return lastFuture . then ( function ( ) { if ( handler !== undefined ) { if ( originalIndexFromCurrentRoutes > 0 ) { var parentRoute = currentRoutes [ originalIndexFromCurrentRoutes - 1 ] var lastValue = parentRoute . route . lastValue } var nextFuture = handler . call ( route , lastValue , distance ) if ( nextFuture !== undefined ) { nextFuture . then ( function ( value ) { route . lastValue = value } ) // no done because nextFuture's errors are handled elsewhere } } if ( nextFuture === undefined ) { nextFuture = Future ( undefined ) } return loopThroughHandlers ( nextFuture , n + 1 ) } ) . catch ( function ( e ) { return handleError ( currentRoutes , originalIndexFromCurrentRoutes , type , e , [ ] ) . then ( function ( ) { if ( direction === 1 ) { return Future ( n + routeVergenceIndex ) } else { // -1 exit handlers return loopThroughHandlers ( Future ( undefined ) , n + 1 ) // continue executing the parent exit handlers } } ) } ) } else { return lastFuture . then ( function ( ) { return Future ( n + routeVergenceIndex ) } ) . catch ( function ( e ) { throw e // propagate the error not the value } ) } }
returns a future that resolves to the maximum depth that succeeded
returns a future that resolves to the maximum depth that succeeded