Comparing version 0.14.2 to 0.14.3
@@ -70,2 +70,11 @@ import { konsole } from './Konsole'; | ||
} | ||
doBefore (handler: Handler<M>) { | ||
return new BeforeRouter(handler, this); | ||
} | ||
doAfter (handler: Handler<M>) { | ||
return new AfterRouter(handler, this); | ||
} | ||
} | ||
@@ -252,8 +261,4 @@ | ||
export function before <M extends Routable> (beforeHandler: Handler<M>, routerOrHandler: RouterOrHandler<M>) { | ||
return new BeforeRouter(beforeHandler, routerOrHandler); | ||
} | ||
export class AfterRouter <M extends Routable> extends Router<M> { | ||
constructor (routerOrHandler: RouterOrHandler<M>, afterHandler: Handler<M>) { | ||
constructor (afterHandler: Handler<M>, routerOrHandler: RouterOrHandler<M>) { | ||
const router = Router.from(routerOrHandler); | ||
@@ -269,6 +274,1 @@ super(m => router.getRoute(m) | ||
} | ||
export function after <M extends Routable> (routerOrHandler: RouterOrHandler<M>, afterHandler: Handler<M>) { | ||
return new AfterRouter(routerOrHandler, afterHandler); | ||
} | ||
@@ -25,2 +25,4 @@ import { Observable } from 'rxjs'; | ||
route(m: M): Observable<any>; | ||
doBefore(handler: Handler<M>): any; | ||
doAfter(handler: Handler<M>): any; | ||
} | ||
@@ -60,6 +62,4 @@ export declare class FirstRouter<M extends Routable> extends Router<M> { | ||
} | ||
export declare function before<M extends Routable>(beforeHandler: Handler<M>, routerOrHandler: RouterOrHandler<M>): BeforeRouter<M>; | ||
export declare class AfterRouter<M extends Routable> extends Router<M> { | ||
constructor(routerOrHandler: RouterOrHandler<M>, afterHandler: Handler<M>); | ||
constructor(afterHandler: Handler<M>, routerOrHandler: RouterOrHandler<M>); | ||
} | ||
export declare function after<M extends Routable>(routerOrHandler: RouterOrHandler<M>, afterHandler: Handler<M>): AfterRouter<M>; |
@@ -67,2 +67,8 @@ "use strict"; | ||
}; | ||
Router.prototype.doBefore = function (handler) { | ||
return new BeforeRouter(handler, this); | ||
}; | ||
Router.prototype.doAfter = function (handler) { | ||
return new AfterRouter(handler, this); | ||
}; | ||
Router.null = new Router(function (m) { return rxjs_1.Observable.empty(); }); | ||
@@ -240,9 +246,5 @@ return Router; | ||
exports.BeforeRouter = BeforeRouter; | ||
function before(beforeHandler, routerOrHandler) { | ||
return new BeforeRouter(beforeHandler, routerOrHandler); | ||
} | ||
exports.before = before; | ||
var AfterRouter = (function (_super) { | ||
__extends(AfterRouter, _super); | ||
function AfterRouter(routerOrHandler, afterHandler) { | ||
function AfterRouter(afterHandler, routerOrHandler) { | ||
var _this = this; | ||
@@ -258,6 +260,2 @@ var router = Router.from(routerOrHandler); | ||
exports.AfterRouter = AfterRouter; | ||
function after(routerOrHandler, afterHandler) { | ||
return new AfterRouter(routerOrHandler, afterHandler); | ||
} | ||
exports.after = after; | ||
//# sourceMappingURL=Router.js.map |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.14.2", | ||
"version": "0.14.3", | ||
"description": "rules-based app engine", | ||
@@ -10,0 +10,0 @@ "main": "dist/prague.js", |
@@ -1156,8 +1156,9 @@ "use strict"; | ||
describe("before", () => { | ||
describe("Router.before", () => { | ||
it("should complete and never emit with null router", (done) => { | ||
before( | ||
throwErr, | ||
Router.null | ||
) | ||
Router | ||
.null | ||
.doBefore( | ||
throwErr | ||
) | ||
.route(foo) | ||
@@ -1167,35 +1168,17 @@ .subscribe(throwErr, passErr, done) | ||
it("should run 'before' handler and then router's action when handler is supplied", (done) => { | ||
let handled; | ||
let routed; | ||
before( | ||
m => { | ||
handled = true; | ||
}, | ||
m => { | ||
expect(handled).to.be.true; | ||
routed = true; | ||
} | ||
) | ||
.route(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
it("should run 'before' handler and then router's action when router is supplied", (done) => { | ||
it("should run 'before' handler and then router's action", (done) => { | ||
let handled; | ||
let routed; | ||
before( | ||
m => { | ||
handled = true; | ||
}, | ||
Router.fromHandler(m => { | ||
Router | ||
.fromHandler(m => { | ||
expect(handled).to.be.true; | ||
routed = true; | ||
}) | ||
) | ||
.doBefore( | ||
m => { | ||
handled = true; | ||
} | ||
) | ||
.route(foo) | ||
@@ -1213,6 +1196,7 @@ .subscribe(n => { | ||
it("should complete and never emit with null router", (done) => { | ||
after( | ||
Router.null, | ||
throwErr | ||
) | ||
Router | ||
.null | ||
.doAfter( | ||
throwErr | ||
) | ||
.route(foo) | ||
@@ -1222,22 +1206,2 @@ .subscribe(throwErr, passErr, done) | ||
it("should run router's action and then 'after' handler when handler is supplied", (done) => { | ||
let handled; | ||
let routed; | ||
after( | ||
m => { | ||
routed = true; | ||
}, | ||
m => { | ||
expect(routed).to.be.true; | ||
handled = true; | ||
} | ||
) | ||
.route(foo) | ||
.subscribe(n => { | ||
expect(handled).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
it("should run router's action and then 'after' router when router is supplied", (done) => { | ||
@@ -1247,11 +1211,12 @@ let handled; | ||
after( | ||
Router.fromHandler(m => { | ||
Router | ||
.fromHandler(m => { | ||
routed = true; | ||
}), | ||
m => { | ||
expect(routed).to.be.true; | ||
handled = true; | ||
} | ||
) | ||
}) | ||
.doAfter( | ||
m => { | ||
expect(routed).to.be.true; | ||
handled = true; | ||
} | ||
) | ||
.route(foo) | ||
@@ -1258,0 +1223,0 @@ .subscribe(n => { |
Sorry, the diff of this file is not supported yet
99
180672
2799