Comparing version 5.0.1 to 5.0.2
export { default } from './router'; | ||
export { default as InternalTransition, PublicTransition as Transition } from './transition'; | ||
export { default as TransitionState } from './transition-state'; | ||
export { default as InternalTransition, PublicTransition as Transition, logAbort, } from './transition'; | ||
export { default as TransitionState, TransitionError } from './transition-state'; | ||
export { default as InternalRouteInfo, RouteInfo, Route } from './route-info'; |
@@ -24,2 +24,8 @@ 'use strict'; | ||
}); | ||
Object.defineProperty(exports, 'logAbort', { | ||
enumerable: true, | ||
get: function get() { | ||
return _transition.logAbort; | ||
} | ||
}); | ||
@@ -34,2 +40,8 @@ var _transitionState = require('./transition-state'); | ||
}); | ||
Object.defineProperty(exports, 'TransitionError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _transitionState.TransitionError; | ||
} | ||
}); | ||
@@ -36,0 +48,0 @@ var _routeInfo = require('./route-info'); |
import { Promise } from 'rsvp'; | ||
import { Dict, Maybe } from './core'; | ||
import { Dict } from './core'; | ||
import Router, { SerializerFunc } from './router'; | ||
@@ -28,10 +28,12 @@ import InternalTransition, { PublicTransition as Transition } from './transition'; | ||
readonly name: string; | ||
readonly parent: Maybe<RouteInfo>; | ||
readonly child: Maybe<RouteInfo>; | ||
readonly parent: RouteInfo | null; | ||
readonly child: RouteInfo | null; | ||
readonly localName: string; | ||
readonly params: Dict<unknown>; | ||
find(predicate: (this: void, routeInfo: RouteInfo, i: number) => boolean, thisArg: any): RouteInfo | undefined; | ||
readonly paramNames: string[]; | ||
readonly queryParams: Dict<unknown>; | ||
find(predicate: (this: any, routeInfo: RouteInfo, i?: number) => boolean, thisArg?: any): RouteInfo | undefined; | ||
} | ||
export declare function toReadOnlyRouteInfo(routeInfos: InternalRouteInfo<Route>[]): { | ||
find(predicate: (this: void, routeInfo: RouteInfo, i: number) => boolean, thisArg: any): RouteInfo | undefined; | ||
export declare function toReadOnlyRouteInfo(routeInfos: InternalRouteInfo<Route>[], queryParams?: Dict<unknown>): { | ||
find(predicate: (this: any, routeInfo: RouteInfo, i?: number | undefined, arr?: RouteInfo[] | undefined) => boolean, thisArg: any): RouteInfo | undefined; | ||
readonly name: string; | ||
@@ -43,3 +45,3 @@ readonly paramNames: string[]; | ||
readonly params: Dict<unknown>; | ||
readonly queryParams: Dict<unknown> | undefined; | ||
readonly queryParams: Dict<unknown>; | ||
}[]; | ||
@@ -76,3 +78,3 @@ export default class InternalRouteInfo<T extends Route> { | ||
constructor(router: Router<T>, name: string, paramNames: string[], params: Dict<unknown>, route: T, context?: Dict<unknown>); | ||
resolve(_shouldContinue?: Continuation, transition?: InternalTransition<T>): Promise<this>; | ||
resolve(_shouldContinue: Continuation, transition: InternalTransition<T>): Promise<InternalRouteInfo<T>>; | ||
} | ||
@@ -79,0 +81,0 @@ export declare class UnresolvedRouteInfoByParam<T extends Route> extends InternalRouteInfo<T> { |
@@ -26,8 +26,9 @@ 'use strict'; | ||
var ROUTE_INFO_LINKS = new WeakMap(); | ||
var ROUTE_INFOS = new WeakMap(); | ||
function toReadOnlyRouteInfo(routeInfos) { | ||
var queryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return routeInfos.map(function (info, i) { | ||
var name = info.name, | ||
params = info.params, | ||
queryParams = info.queryParams, | ||
paramNames = info.paramNames; | ||
@@ -43,8 +44,12 @@ | ||
value: function find(predicate, thisArg) { | ||
var routeInfo = void 0; | ||
var publicInfo = void 0; | ||
var arr = []; | ||
if (predicate.length === 3) { | ||
arr = routeInfos.map(function (info) { | ||
return ROUTE_INFOS.get(info); | ||
}); | ||
} | ||
for (var _i = 0; routeInfos.length > 0; _i++) { | ||
routeInfo = routeInfos[_i]; | ||
publicInfo = ROUTE_INFO_LINKS.get(routeInfo); | ||
if (predicate.call(thisArg, publicInfo, _i)) { | ||
publicInfo = ROUTE_INFOS.get(routeInfos[_i]); | ||
if (predicate.call(thisArg, publicInfo, _i, arr)) { | ||
return publicInfo; | ||
@@ -69,3 +74,6 @@ } | ||
var parent = routeInfos[i - 1]; | ||
return parent === undefined ? null : ROUTE_INFO_LINKS.get(routeInfos[i - 1]); | ||
if (parent === undefined) { | ||
return null; | ||
} | ||
return ROUTE_INFOS.get(parent); | ||
} | ||
@@ -76,3 +84,6 @@ }, { | ||
var child = routeInfos[i + 1]; | ||
return child === undefined ? null : ROUTE_INFO_LINKS.get(routeInfos[i + 1]); | ||
if (child === undefined) { | ||
return null; | ||
} | ||
return ROUTE_INFOS.get(child); | ||
} | ||
@@ -99,3 +110,3 @@ }, { | ||
}())(); | ||
ROUTE_INFO_LINKS.set(info, publicRouteInfo); | ||
ROUTE_INFOS.set(info, publicRouteInfo); | ||
return publicRouteInfo; | ||
@@ -138,11 +149,11 @@ }); | ||
return _this.checkForAbort(shouldContinue, route); | ||
}, null).then(function () { | ||
}).then(function () { | ||
return _this.runBeforeModelHook(transition); | ||
}, null).then(function () { | ||
}).then(function () { | ||
return _this.checkForAbort(shouldContinue, null); | ||
}, null).then(function () { | ||
}).then(function () { | ||
return _this.getModel(transition); | ||
}).then(function (resolvedModel) { | ||
return _this.checkForAbort(shouldContinue, resolvedModel); | ||
}, null).then(function (resolvedModel) { | ||
}).then(function (resolvedModel) { | ||
return _this.runAfterModelHook(transition, resolvedModel); | ||
@@ -167,3 +178,8 @@ }).then(function (resolvedModel) { | ||
} | ||
return new ResolvedRouteInfo(this.router, this.name, this.paramNames, params, this.route, context); | ||
var cached = ROUTE_INFOS.get(this); | ||
var resolved = new ResolvedRouteInfo(this.router, this.name, this.paramNames, params, this.route, context); | ||
if (cached !== undefined) { | ||
ROUTE_INFOS.set(resolved, cached); | ||
} | ||
return resolved; | ||
} | ||
@@ -170,0 +186,0 @@ }, { |
@@ -7,3 +7,3 @@ import RouteRecognizer, { MatchCallback } from 'route-recognizer'; | ||
import { TransitionIntent } from './transition-intent'; | ||
import TransitionState from './transition-state'; | ||
import TransitionState, { TransitionError } from './transition-state'; | ||
import { ChangeList } from './utils'; | ||
@@ -34,2 +34,5 @@ export interface SerializerFunc { | ||
abstract triggerEvent(routeInfos: InternalRouteInfo<T>[], ignoreFailure: boolean, name: string, args: unknown[]): void; | ||
abstract routeWillChange(transition: Transition): void; | ||
abstract routeDidChange(transition: Transition): void; | ||
abstract transitionDidError(error: TransitionError, transition: Transition): Transition | Error; | ||
/** | ||
@@ -167,2 +170,5 @@ The main entry point into the router. The API is essentially | ||
private finalizeQueryParamChange; | ||
private toReadOnlyInfos; | ||
private fromInfos; | ||
private toInfos; | ||
private notifyExistingHandlers; | ||
@@ -169,0 +175,0 @@ /** |
@@ -103,7 +103,9 @@ 'use strict'; | ||
oldState.queryParams = this.finalizeQueryParamChange(newState.routeInfos, newState.queryParams, newTransition); | ||
newTransition.queryParams = newState.queryParams; | ||
this.toReadOnlyInfos(newTransition, newState.routeInfos); | ||
this.routeWillChange(newTransition); | ||
newTransition.promise = newTransition.promise.then(function (result) { | ||
_this._updateURL(newTransition, oldState); | ||
if (_this.didTransition) { | ||
_this.didTransition(_this.currentRouteInfos); | ||
} | ||
_this.routeDidChange(newTransition); | ||
_this.didTransition(_this.currentRouteInfos); | ||
return result; | ||
@@ -145,2 +147,4 @@ }, null, (0, _utils.promiseLabel)('Transition complete')); | ||
this.setupContexts(newState); | ||
this.toInfos(this.activeTransition, newState.routeInfos); | ||
this.routeWillChange(this.activeTransition); | ||
return this.activeTransition; | ||
@@ -155,5 +159,6 @@ } | ||
} | ||
this.toReadOnlyInfos(newTransition, newState.routeInfos); | ||
// Abort and usurp any previously active transition. | ||
if (this.activeTransition) { | ||
this.activeTransition.abort(); | ||
this.activeTransition.redirect(newTransition); | ||
} | ||
@@ -235,5 +240,4 @@ this.activeTransition = newTransition; | ||
this.triggerEvent(this.currentRouteInfos, true, 'didTransition', []); | ||
if (this.didTransition) { | ||
this.didTransition(this.currentRouteInfos); | ||
} | ||
this.routeDidChange(transition); | ||
this.didTransition(this.currentRouteInfos); | ||
(0, _utils.log)(this, transition.sequence, 'TRANSITION COMPLETE.'); | ||
@@ -244,3 +248,2 @@ // Resolve with the final route. | ||
if (!(e instanceof _transitionAbortedError2.default)) { | ||
//let erroneousHandler = routeInfos.pop(); | ||
var infos = transition.state.routeInfos; | ||
@@ -553,2 +556,25 @@ transition.trigger(true, 'error', e, transition, infos[infos.length - 1].route); | ||
}, { | ||
key: 'toReadOnlyInfos', | ||
value: function toReadOnlyInfos(newTransition, newRouteInfos) { | ||
var oldRouteInfos = this.state.routeInfos; | ||
this.fromInfos(newTransition, oldRouteInfos); | ||
this.toInfos(newTransition, newRouteInfos); | ||
} | ||
}, { | ||
key: 'fromInfos', | ||
value: function fromInfos(newTransition, oldRouteInfos) { | ||
if (oldRouteInfos.length > 0) { | ||
var fromInfos = (0, _routeInfo.toReadOnlyRouteInfo)(oldRouteInfos, newTransition.queryParams); | ||
newTransition.from = fromInfos[fromInfos.length - 1] || null; | ||
} | ||
} | ||
}, { | ||
key: 'toInfos', | ||
value: function toInfos(newTransition, newRouteInfos) { | ||
if (newRouteInfos.length > 0) { | ||
var toInfos = (0, _routeInfo.toReadOnlyRouteInfo)(newRouteInfos, newTransition.queryParams); | ||
newTransition.to = toInfos[toInfos.length - 1] || null; | ||
} | ||
} | ||
}, { | ||
key: 'notifyExistingHandlers', | ||
@@ -573,14 +599,5 @@ value: function notifyExistingHandlers(newState, newTransition) { | ||
} | ||
if (oldRouteInfoLen > 0) { | ||
var fromInfos = (0, _routeInfo.toReadOnlyRouteInfo)(oldRouteInfos); | ||
newTransition.from = fromInfos[fromInfos.length - 1]; | ||
} | ||
if (newState.routeInfos.length > 0) { | ||
var toInfos = (0, _routeInfo.toReadOnlyRouteInfo)(newState.routeInfos); | ||
newTransition.to = toInfos[toInfos.length - 1]; | ||
} | ||
this.triggerEvent(oldRouteInfos, true, 'willTransition', [newTransition]); | ||
if (this.willTransition) { | ||
this.willTransition(oldRouteInfos, newState.routeInfos, newTransition); | ||
} | ||
this.routeWillChange(newTransition); | ||
this.willTransition(oldRouteInfos, newState.routeInfos, newTransition); | ||
} | ||
@@ -587,0 +604,0 @@ /** |
@@ -68,3 +68,7 @@ 'use strict'; | ||
var name = result.handler; | ||
var newRouteInfo = new _routeInfo.UnresolvedRouteInfoByParam(this.router, name, [], result.params); | ||
var paramNames = []; | ||
if (this.router.recognizer.hasRoute(name)) { | ||
paramNames = this.router.recognizer.handlersFor(name)[i].names; | ||
} | ||
var newRouteInfo = new _routeInfo.UnresolvedRouteInfoByParam(this.router, name, paramNames, result.params); | ||
var route = newRouteInfo.route; | ||
@@ -71,0 +75,0 @@ if (route) { |
@@ -29,4 +29,4 @@ import { Promise } from 'rsvp'; | ||
state?: TransitionState<T>; | ||
from: Maybe<RouteInfo>; | ||
to: Maybe<RouteInfo>; | ||
from?: RouteInfo; | ||
to?: RouteInfo; | ||
router: Router<T>; | ||
@@ -132,2 +132,4 @@ data: Dict<unknown>; | ||
abort(): this; | ||
rollback(): void; | ||
redirect(newTransition: Transition<T>): void; | ||
/** | ||
@@ -134,0 +136,0 @@ |
@@ -49,4 +49,4 @@ 'use strict'; | ||
this.from = null; | ||
this.to = null; | ||
this.from = undefined; | ||
this.to = undefined; | ||
this.isAborted = false; | ||
@@ -111,9 +111,3 @@ this.isActive = true; | ||
}, this).catch(function (result) { | ||
if (result.wasAborted || _this.isAborted) { | ||
return _rsvp.Promise.reject(logAbort(_this)); | ||
} else { | ||
_this.trigger(false, 'error', result.error, _this, result.route); | ||
_this.abort(); | ||
return _rsvp.Promise.reject(result.error); | ||
} | ||
return _rsvp.Promise.reject(_this.router.transitionDidError(result, _this)); | ||
}, (0, _utils.promiseLabel)('Handle Abort')); | ||
@@ -212,14 +206,30 @@ } else { | ||
value: function abort() { | ||
if (this.isAborted) { | ||
return this; | ||
} | ||
(0, _utils.log)(this.router, this.sequence, this.targetName + ': transition was aborted'); | ||
if (this.intent !== undefined && this.intent !== null) { | ||
this.intent.preTransitionState = this.router.state; | ||
} | ||
this.isAborted = true; | ||
this.isActive = false; | ||
this.router.activeTransition = undefined; | ||
this.rollback(); | ||
var transition = new Transition(this.router, undefined, undefined, undefined); | ||
transition.to = this.from; | ||
transition.from = this.from; | ||
transition.isAborted = true; | ||
this.router.routeWillChange(transition); | ||
this.router.routeDidChange(transition); | ||
return this; | ||
} | ||
}, { | ||
key: 'rollback', | ||
value: function rollback() { | ||
if (!this.isAborted) { | ||
(0, _utils.log)(this.router, this.sequence, this.targetName + ': transition was aborted'); | ||
if (this.intent !== undefined && this.intent !== null) { | ||
this.intent.preTransitionState = this.router.state; | ||
} | ||
this.isAborted = true; | ||
this.isActive = false; | ||
this.router.activeTransition = undefined; | ||
} | ||
} | ||
}, { | ||
key: 'redirect', | ||
value: function redirect(newTransition) { | ||
this.rollback(); | ||
this.router.routeWillChange(newTransition); | ||
} | ||
/** | ||
@@ -226,0 +236,0 @@ Retries a previously-aborted transition (making sure to abort the |
export { default } from './router'; | ||
export { default as InternalTransition, PublicTransition as Transition } from './transition'; | ||
export { default as TransitionState } from './transition-state'; | ||
export { default as InternalTransition, PublicTransition as Transition, logAbort, } from './transition'; | ||
export { default as TransitionState, TransitionError } from './transition-state'; | ||
export { default as InternalRouteInfo, RouteInfo, Route } from './route-info'; |
export { default } from './router'; | ||
export { default as InternalTransition } from './transition'; | ||
export { default as TransitionState } from './transition-state'; | ||
export { default as InternalTransition, logAbort, } from './transition'; | ||
export { default as TransitionState, TransitionError } from './transition-state'; | ||
export { default as InternalRouteInfo } from './route-info'; | ||
//# sourceMappingURL=index.js.map |
import { Promise } from 'rsvp'; | ||
import { Dict, Maybe } from './core'; | ||
import { Dict } from './core'; | ||
import Router, { SerializerFunc } from './router'; | ||
@@ -28,10 +28,12 @@ import InternalTransition, { PublicTransition as Transition } from './transition'; | ||
readonly name: string; | ||
readonly parent: Maybe<RouteInfo>; | ||
readonly child: Maybe<RouteInfo>; | ||
readonly parent: RouteInfo | null; | ||
readonly child: RouteInfo | null; | ||
readonly localName: string; | ||
readonly params: Dict<unknown>; | ||
find(predicate: (this: void, routeInfo: RouteInfo, i: number) => boolean, thisArg: any): RouteInfo | undefined; | ||
readonly paramNames: string[]; | ||
readonly queryParams: Dict<unknown>; | ||
find(predicate: (this: any, routeInfo: RouteInfo, i?: number) => boolean, thisArg?: any): RouteInfo | undefined; | ||
} | ||
export declare function toReadOnlyRouteInfo(routeInfos: InternalRouteInfo<Route>[]): { | ||
find(predicate: (this: void, routeInfo: RouteInfo, i: number) => boolean, thisArg: any): RouteInfo | undefined; | ||
export declare function toReadOnlyRouteInfo(routeInfos: InternalRouteInfo<Route>[], queryParams?: Dict<unknown>): { | ||
find(predicate: (this: any, routeInfo: RouteInfo, i?: number | undefined, arr?: RouteInfo[] | undefined) => boolean, thisArg: any): RouteInfo | undefined; | ||
readonly name: string; | ||
@@ -43,3 +45,3 @@ readonly paramNames: string[]; | ||
readonly params: Dict<unknown>; | ||
readonly queryParams: Dict<unknown> | undefined; | ||
readonly queryParams: Dict<unknown>; | ||
}[]; | ||
@@ -76,3 +78,3 @@ export default class InternalRouteInfo<T extends Route> { | ||
constructor(router: Router<T>, name: string, paramNames: string[], params: Dict<unknown>, route: T, context?: Dict<unknown>); | ||
resolve(_shouldContinue?: Continuation, transition?: InternalTransition<T>): Promise<this>; | ||
resolve(_shouldContinue: Continuation, transition: InternalTransition<T>): Promise<InternalRouteInfo<T>>; | ||
} | ||
@@ -79,0 +81,0 @@ export declare class UnresolvedRouteInfoByParam<T extends Route> extends InternalRouteInfo<T> { |
import { Promise } from 'rsvp'; | ||
import { isTransition, prepareResult, } from './transition'; | ||
import { isParam, isPromise, merge } from './utils'; | ||
let ROUTE_INFO_LINKS = new WeakMap(); | ||
export function toReadOnlyRouteInfo(routeInfos) { | ||
let ROUTE_INFOS = new WeakMap(); | ||
export function toReadOnlyRouteInfo(routeInfos, queryParams = {}) { | ||
return routeInfos.map((info, i) => { | ||
let { name, params, queryParams, paramNames } = info; | ||
let { name, params, paramNames } = info; | ||
let publicRouteInfo = new class { | ||
find(predicate, thisArg) { | ||
let routeInfo; | ||
let publicInfo; | ||
let arr = []; | ||
if (predicate.length === 3) { | ||
arr = routeInfos.map(info => ROUTE_INFOS.get(info)); | ||
} | ||
for (let i = 0; routeInfos.length > 0; i++) { | ||
routeInfo = routeInfos[i]; | ||
publicInfo = ROUTE_INFO_LINKS.get(routeInfo); | ||
if (predicate.call(thisArg, publicInfo, i)) { | ||
publicInfo = ROUTE_INFOS.get(routeInfos[i]); | ||
if (predicate.call(thisArg, publicInfo, i, arr)) { | ||
return publicInfo; | ||
@@ -29,7 +31,13 @@ } | ||
let parent = routeInfos[i - 1]; | ||
return parent === undefined ? null : ROUTE_INFO_LINKS.get(routeInfos[i - 1]); | ||
if (parent === undefined) { | ||
return null; | ||
} | ||
return ROUTE_INFOS.get(parent); | ||
} | ||
get child() { | ||
let child = routeInfos[i + 1]; | ||
return child === undefined ? null : ROUTE_INFO_LINKS.get(routeInfos[i + 1]); | ||
if (child === undefined) { | ||
return null; | ||
} | ||
return ROUTE_INFOS.get(child); | ||
} | ||
@@ -47,3 +55,3 @@ get localName() { | ||
}(); | ||
ROUTE_INFO_LINKS.set(info, publicRouteInfo); | ||
ROUTE_INFOS.set(info, publicRouteInfo); | ||
return publicRouteInfo; | ||
@@ -73,9 +81,7 @@ }); | ||
return Promise.resolve(this.routePromise) | ||
.then((route) => this.checkForAbort(shouldContinue, route), null) | ||
.then(() => { | ||
return this.runBeforeModelHook(transition); | ||
}, null) | ||
.then(() => this.checkForAbort(shouldContinue, null), null) | ||
.then((route) => this.checkForAbort(shouldContinue, route)) | ||
.then(() => this.runBeforeModelHook(transition)) | ||
.then(() => this.checkForAbort(shouldContinue, null)) | ||
.then(() => this.getModel(transition)) | ||
.then(resolvedModel => this.checkForAbort(shouldContinue, resolvedModel), null) | ||
.then(resolvedModel => this.checkForAbort(shouldContinue, resolvedModel)) | ||
.then(resolvedModel => this.runAfterModelHook(transition, resolvedModel)) | ||
@@ -96,3 +102,8 @@ .then(resolvedModel => this.becomeResolved(transition, resolvedModel)); | ||
} | ||
return new ResolvedRouteInfo(this.router, this.name, this.paramNames, params, this.route, context); | ||
let cached = ROUTE_INFOS.get(this); | ||
let resolved = new ResolvedRouteInfo(this.router, this.name, this.paramNames, params, this.route, context); | ||
if (cached !== undefined) { | ||
ROUTE_INFOS.set(resolved, cached); | ||
} | ||
return resolved; | ||
} | ||
@@ -99,0 +110,0 @@ shouldSupercede(routeInfo) { |
@@ -7,3 +7,3 @@ import RouteRecognizer, { MatchCallback } from 'route-recognizer'; | ||
import { TransitionIntent } from './transition-intent'; | ||
import TransitionState from './transition-state'; | ||
import TransitionState, { TransitionError } from './transition-state'; | ||
import { ChangeList } from './utils'; | ||
@@ -34,2 +34,5 @@ export interface SerializerFunc { | ||
abstract triggerEvent(routeInfos: InternalRouteInfo<T>[], ignoreFailure: boolean, name: string, args: unknown[]): void; | ||
abstract routeWillChange(transition: Transition): void; | ||
abstract routeDidChange(transition: Transition): void; | ||
abstract transitionDidError(error: TransitionError, transition: Transition): Transition | Error; | ||
/** | ||
@@ -167,2 +170,5 @@ The main entry point into the router. The API is essentially | ||
private finalizeQueryParamChange; | ||
private toReadOnlyInfos; | ||
private fromInfos; | ||
private toInfos; | ||
private notifyExistingHandlers; | ||
@@ -169,0 +175,0 @@ /** |
@@ -61,7 +61,9 @@ import RouteRecognizer from 'route-recognizer'; | ||
oldState.queryParams = this.finalizeQueryParamChange(newState.routeInfos, newState.queryParams, newTransition); | ||
newTransition.queryParams = newState.queryParams; | ||
this.toReadOnlyInfos(newTransition, newState.routeInfos); | ||
this.routeWillChange(newTransition); | ||
newTransition.promise = newTransition.promise.then((result) => { | ||
this._updateURL(newTransition, oldState); | ||
if (this.didTransition) { | ||
this.didTransition(this.currentRouteInfos); | ||
} | ||
this.routeDidChange(newTransition); | ||
this.didTransition(this.currentRouteInfos); | ||
return result; | ||
@@ -98,2 +100,4 @@ }, null, promiseLabel('Transition complete')); | ||
this.setupContexts(newState); | ||
this.toInfos(this.activeTransition, newState.routeInfos); | ||
this.routeWillChange(this.activeTransition); | ||
return this.activeTransition; | ||
@@ -108,5 +112,6 @@ } | ||
} | ||
this.toReadOnlyInfos(newTransition, newState.routeInfos); | ||
// Abort and usurp any previously active transition. | ||
if (this.activeTransition) { | ||
this.activeTransition.abort(); | ||
this.activeTransition.redirect(newTransition); | ||
} | ||
@@ -183,5 +188,4 @@ this.activeTransition = newTransition; | ||
this.triggerEvent(this.currentRouteInfos, true, 'didTransition', []); | ||
if (this.didTransition) { | ||
this.didTransition(this.currentRouteInfos); | ||
} | ||
this.routeDidChange(transition); | ||
this.didTransition(this.currentRouteInfos); | ||
log(this, transition.sequence, 'TRANSITION COMPLETE.'); | ||
@@ -193,3 +197,2 @@ // Resolve with the final route. | ||
if (!(e instanceof TransitionAbortedError)) { | ||
//let erroneousHandler = routeInfos.pop(); | ||
let infos = transition.state.routeInfos; | ||
@@ -505,2 +508,19 @@ transition.trigger(true, 'error', e, transition, infos[infos.length - 1].route); | ||
} | ||
toReadOnlyInfos(newTransition, newRouteInfos) { | ||
let oldRouteInfos = this.state.routeInfos; | ||
this.fromInfos(newTransition, oldRouteInfos); | ||
this.toInfos(newTransition, newRouteInfos); | ||
} | ||
fromInfos(newTransition, oldRouteInfos) { | ||
if (oldRouteInfos.length > 0) { | ||
let fromInfos = toReadOnlyRouteInfo(oldRouteInfos, newTransition.queryParams); | ||
newTransition.from = fromInfos[fromInfos.length - 1] || null; | ||
} | ||
} | ||
toInfos(newTransition, newRouteInfos) { | ||
if (newRouteInfos.length > 0) { | ||
let toInfos = toReadOnlyRouteInfo(newRouteInfos, newTransition.queryParams); | ||
newTransition.to = toInfos[toInfos.length - 1] || null; | ||
} | ||
} | ||
notifyExistingHandlers(newState, newTransition) { | ||
@@ -519,14 +539,5 @@ let oldRouteInfos = this.state.routeInfos, changing = [], i, oldRouteInfoLen, oldHandler, newRouteInfo; | ||
} | ||
if (oldRouteInfoLen > 0) { | ||
let fromInfos = toReadOnlyRouteInfo(oldRouteInfos); | ||
newTransition.from = fromInfos[fromInfos.length - 1]; | ||
} | ||
if (newState.routeInfos.length > 0) { | ||
let toInfos = toReadOnlyRouteInfo(newState.routeInfos); | ||
newTransition.to = toInfos[toInfos.length - 1]; | ||
} | ||
this.triggerEvent(oldRouteInfos, true, 'willTransition', [newTransition]); | ||
if (this.willTransition) { | ||
this.willTransition(oldRouteInfos, newState.routeInfos, newTransition); | ||
} | ||
this.routeWillChange(newTransition); | ||
this.willTransition(oldRouteInfos, newState.routeInfos, newTransition); | ||
} | ||
@@ -533,0 +544,0 @@ /** |
@@ -32,3 +32,7 @@ import { UnresolvedRouteInfoByParam } from '../route-info'; | ||
let name = result.handler; | ||
let newRouteInfo = new UnresolvedRouteInfoByParam(this.router, name, [], result.params); | ||
let paramNames = []; | ||
if (this.router.recognizer.hasRoute(name)) { | ||
paramNames = this.router.recognizer.handlersFor(name)[i].names; | ||
} | ||
let newRouteInfo = new UnresolvedRouteInfoByParam(this.router, name, paramNames, result.params); | ||
let route = newRouteInfo.route; | ||
@@ -35,0 +39,0 @@ if (route) { |
@@ -29,4 +29,4 @@ import { Promise } from 'rsvp'; | ||
state?: TransitionState<T>; | ||
from: Maybe<RouteInfo>; | ||
to: Maybe<RouteInfo>; | ||
from?: RouteInfo; | ||
to?: RouteInfo; | ||
router: Router<T>; | ||
@@ -132,2 +132,4 @@ data: Dict<unknown>; | ||
abort(): this; | ||
rollback(): void; | ||
redirect(newTransition: Transition<T>): void; | ||
/** | ||
@@ -134,0 +136,0 @@ |
@@ -21,4 +21,4 @@ import { Promise } from 'rsvp'; | ||
constructor(router, intent, state, error = undefined, previousTransition = undefined) { | ||
this.from = null; | ||
this.to = null; | ||
this.from = undefined; | ||
this.to = undefined; | ||
this.isAborted = false; | ||
@@ -91,10 +91,3 @@ this.isActive = true; | ||
.catch((result) => { | ||
if (result.wasAborted || this.isAborted) { | ||
return Promise.reject(logAbort(this)); | ||
} | ||
else { | ||
this.trigger(false, 'error', result.error, this, result.route); | ||
this.abort(); | ||
return Promise.reject(result.error); | ||
} | ||
return Promise.reject(this.router.transitionDidError(result, this)); | ||
}, promiseLabel('Handle Abort')); | ||
@@ -190,14 +183,26 @@ } | ||
abort() { | ||
if (this.isAborted) { | ||
return this; | ||
} | ||
log(this.router, this.sequence, this.targetName + ': transition was aborted'); | ||
if (this.intent !== undefined && this.intent !== null) { | ||
this.intent.preTransitionState = this.router.state; | ||
} | ||
this.isAborted = true; | ||
this.isActive = false; | ||
this.router.activeTransition = undefined; | ||
this.rollback(); | ||
let transition = new Transition(this.router, undefined, undefined, undefined); | ||
transition.to = this.from; | ||
transition.from = this.from; | ||
transition.isAborted = true; | ||
this.router.routeWillChange(transition); | ||
this.router.routeDidChange(transition); | ||
return this; | ||
} | ||
rollback() { | ||
if (!this.isAborted) { | ||
log(this.router, this.sequence, this.targetName + ': transition was aborted'); | ||
if (this.intent !== undefined && this.intent !== null) { | ||
this.intent.preTransitionState = this.router.state; | ||
} | ||
this.isAborted = true; | ||
this.isActive = false; | ||
this.router.activeTransition = undefined; | ||
} | ||
} | ||
redirect(newTransition) { | ||
this.rollback(); | ||
this.router.routeWillChange(newTransition); | ||
} | ||
/** | ||
@@ -204,0 +209,0 @@ |
{ | ||
"name": "router_js", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": | ||
@@ -5,0 +5,0 @@ "A lightweight JavaScript library is built on top of route-recognizer and rsvp.js to provide an API for handling routes", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
360116
5245