Comparing version 0.0.7 to 0.0.8
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ import { IRouteTransitionRedirectOptions } from "./types"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IHistory, IHistoryNavigateEvent } from "../types"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IHistory, IHistoryNavigateEvent } from "../types"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IHistory, IHistoryNavigateEvent } from "../types"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IRouteTemplate, IRouteMapper, IRouteParser, IRouteResolver, IRouteConstructable, MappingFunction } from "./types"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IRouteParser, IRouteParseResult } from "./types"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IRoute, IRouteParameters, IRouteInfo, IRouteTransitionPromiseResult, IRouteCancelableTransitionPromiseResult } from "./types"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IRouter, IRoute, IRouteTemplate, RouterContext, MappingFunction, IRouterOptions, IRouterNavigateOptions } from "./types"; |
@@ -98,15 +98,11 @@ "use strict"; | ||
})); | ||
transition.promise.catch(function (e) { | ||
if (e instanceof Errors_1.RedirectedError) { | ||
_this.navigate(e.redirectOptions.url, { | ||
replace: e.redirectOptions.replace | ||
transition.promise.then(function (reason) { | ||
if (reason) { | ||
return; | ||
} | ||
if (reason instanceof Errors_1.RedirectedError) { | ||
_this.navigate(reason.redirectOptions.url, { | ||
replace: reason.redirectOptions.replace | ||
}); | ||
} | ||
else if (e instanceof Errors_1.CancellationError || | ||
e instanceof Errors_1.InterceptedError || | ||
e instanceof Errors_1.ReplacedError) { | ||
} | ||
else { | ||
throw e; | ||
} | ||
}); | ||
@@ -113,0 +109,0 @@ return transition.promise; |
@@ -0,0 +0,0 @@ import { IRoute, ITransitor, TransitionConflictStrategy, ITransition } from "./types"; |
"use strict"; | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
var types_1 = require("./types"); | ||
var Errors_1 = require('./Errors'); | ||
var StopTransactionError = (function (_super) { | ||
__extends(StopTransactionError, _super); | ||
function StopTransactionError() { | ||
_super.apply(this, arguments); | ||
} | ||
return StopTransactionError; | ||
}(Error)); | ||
var Transition = (function () { | ||
@@ -63,9 +75,30 @@ function Transition(parent, newRoute, start) { | ||
}); | ||
Transition.prototype.stop = function (reason) { | ||
if (reason instanceof Errors_1.ReplacedError) { | ||
this._promiseReject(reason); | ||
} | ||
else if (reason instanceof Errors_1.InterceptedError) { | ||
this._state = types_1.TransitionState.Intercepted; | ||
} | ||
else if (reason instanceof Errors_1.CancellationError) { | ||
this._state = types_1.TransitionState.Cancelled; | ||
} | ||
else if (reason instanceof Errors_1.RedirectedError) { | ||
this._state = types_1.TransitionState.Redirected; | ||
} | ||
if (this.state === types_1.TransitionState.InOldRoute && this.oldRoute && !(reason instanceof Errors_1.ReplacedError)) { | ||
this.oldRoute.onCancelExitTransition(reason); | ||
} | ||
this.newRoute.onCancelEnterTransition(reason); | ||
this._promiseResolve(reason); | ||
}; | ||
Transition.prototype.interceptTransition = function (transitionResult) { | ||
if (this.canceled) { | ||
if (this.inProgress && this.state !== types_1.TransitionState.Started) { | ||
throw new Errors_1.InterceptedError("Intercepted: " + this._canceled); | ||
this.stop(new Errors_1.InterceptedError("Intercepted: " + this._canceled)); | ||
throw new StopTransactionError(); | ||
} | ||
else { | ||
throw new Errors_1.ReplacedError("Replaced: " + this._canceled); | ||
this.stop(new Errors_1.ReplacedError("Replaced: " + this._canceled)); | ||
throw new StopTransactionError(); | ||
} | ||
@@ -77,6 +110,8 @@ } | ||
if (transitionResult.canceled) { | ||
throw new Errors_1.CancellationError("Canceled by route"); | ||
this.stop(new Errors_1.CancellationError("Canceled by route")); | ||
throw new StopTransactionError(); | ||
} | ||
if (transitionResult.redirected) { | ||
throw new Errors_1.RedirectedError("Redirected by route", transitionResult.redirected); | ||
this.stop(new Errors_1.RedirectedError("Redirected by route", transitionResult.redirected)); | ||
throw new StopTransactionError(); | ||
} | ||
@@ -114,35 +149,5 @@ }; | ||
}).catch(function (e) { | ||
if (e instanceof Errors_1.ReplacedError) { | ||
_this._state = types_1.TransitionState.Replaced; | ||
_this.newRoute.onCancelEnterTransition(e); | ||
if (!(e instanceof StopTransactionError)) { | ||
_this._promiseReject(e); | ||
} | ||
else if (e instanceof Errors_1.InterceptedError) { | ||
_this._state = types_1.TransitionState.Intercepted; | ||
if (_this.state === types_1.TransitionState.InOldRoute && _this.oldRoute) { | ||
_this.oldRoute.onCancelExitTransition(e); | ||
} | ||
_this.newRoute.onCancelEnterTransition(e); | ||
_this._promiseReject(e); | ||
} | ||
else if (e instanceof Errors_1.CancellationError) { | ||
_this._state = types_1.TransitionState.Cancelled; | ||
if (_this.state === types_1.TransitionState.InOldRoute && _this.oldRoute) { | ||
_this.oldRoute.onCancelExitTransition(e); | ||
} | ||
_this.newRoute.onCancelEnterTransition(e); | ||
_this._promiseReject(e); | ||
} | ||
else if (e instanceof Errors_1.RedirectedError) { | ||
_this._state = types_1.TransitionState.Redirected; | ||
if (_this.state === types_1.TransitionState.InOldRoute && _this.oldRoute) { | ||
_this.oldRoute.onCancelExitTransition(e); | ||
} | ||
_this.newRoute.onCancelEnterTransition(e); | ||
_this._promiseReject(e); | ||
} | ||
else { | ||
_this._promiseReject(e); | ||
throw e; | ||
} | ||
}); | ||
@@ -149,0 +154,0 @@ }; |
@@ -89,3 +89,3 @@ /** | ||
inProgress: boolean; | ||
promise: Promise<void>; | ||
promise: Promise<Error>; | ||
start(): void; | ||
@@ -92,0 +92,0 @@ cancel(reason: string): void; |
@@ -0,0 +0,0 @@ /* Router */ |
export declare function normalizePath(path: string): string; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "steersman", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Lightweight JS router for browsers & node", | ||
@@ -5,0 +5,0 @@ "main": "lib/router.js", |
@@ -0,0 +0,0 @@ # Steersman |
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
110533
38
993