Comparing version 0.15.3 to 0.15.8
@@ -33,3 +33,3 @@ import { konsole } from './Konsole'; | ||
export class Router <ROUTABLE> { | ||
constructor(public getRoute: (routable: ROUTABLE) => Observable<Route>) {} | ||
constructor(public getRoute$: (routable: ROUTABLE) => Observable<Route>) {} | ||
@@ -69,11 +69,19 @@ static actionRoute ( | ||
route (routable: ROUTABLE) { | ||
route$ (routable: ROUTABLE) { | ||
return this | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.do(route => konsole.log("route: returned a route", route)) | ||
.filter(route => route.type === 'action') | ||
.flatMap((route: ActionRoute) => toObservable(route.action())) | ||
.do(_ => konsole.log("route: called action")); | ||
.flatMap(route => route.type === 'action' | ||
? toObservable(route.action()) | ||
.do(_ => konsole.log("route: called action")) | ||
.map(_ => true) | ||
: Observable.of(false) | ||
); | ||
} | ||
route (routable: ROUTABLE) { | ||
return this.route$(routable) | ||
.toPromise(); | ||
} | ||
beforeDo (handler: Handler<ROUTABLE>) { | ||
@@ -114,5 +122,9 @@ return new BeforeRouter<ROUTABLE>(handler, this); | ||
ifTrue (predicate: Predicate<ROUTABLE>): IfTrue<ROUTABLE> { | ||
ifTrue (predicate: Predicate<ROUTABLE>) { | ||
return new IfTrue(predicate); | ||
} | ||
route (routable: ROUTABLE, router: Router<ROUTABLE>) { | ||
return router.route(routable); | ||
} | ||
} | ||
@@ -127,3 +139,3 @@ | ||
return router | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.do(route => konsole.log(`first: router #${i} returned route`, route)); | ||
@@ -153,3 +165,3 @@ }) | ||
.takeWhile(_ => bestRoute.score < 1) | ||
.concatMap(router => router.getRoute(routable)) | ||
.concatMap(router => router.getRoute$(routable)) | ||
.filter(route => route.type === 'action') | ||
@@ -228,3 +240,3 @@ .defaultIfEmpty(Router.noRoute('tryInScoreOrder')) | ||
? getThenRouter(match.value) | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(route => route.type === 'action' | ||
@@ -235,3 +247,3 @@ ? routeWithCombinedScore(route, match.score) | ||
: getElseRouter(match.reason) | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
) | ||
@@ -251,3 +263,3 @@ ); | ||
? getThenRouter(match.value) | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(route => route.type === 'action' | ||
@@ -395,3 +407,3 @@ ? routeWithCombinedScore(route, match.score) | ||
super(routable => router | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(route => route.type === 'action' | ||
@@ -412,3 +424,3 @@ ? { | ||
super(routable => router | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(route => route.type === 'action' | ||
@@ -431,6 +443,6 @@ ? { | ||
) { | ||
super(routable => mainRouter.getRoute(routable) | ||
super(routable => mainRouter.getRoute$(routable) | ||
.flatMap(route => route.type === 'action' | ||
? Observable.of(route) | ||
: getDefaultRouter(route.reason).getRoute(routable) | ||
: getDefaultRouter(route.reason).getRoute$(routable) | ||
) | ||
@@ -437,0 +449,0 @@ ); |
@@ -17,4 +17,4 @@ import { Observable } from 'rxjs'; | ||
export declare class Router<ROUTABLE> { | ||
getRoute: (routable: ROUTABLE) => Observable<Route>; | ||
constructor(getRoute: (routable: ROUTABLE) => Observable<Route>); | ||
getRoute$: (routable: ROUTABLE) => Observable<Route>; | ||
constructor(getRoute$: (routable: ROUTABLE) => Observable<Route>); | ||
static actionRoute(action: () => Observableable<any>, score?: number): ActionRoute; | ||
@@ -25,3 +25,4 @@ static do<ROUTABLE>(handler: Handler<ROUTABLE>, score?: number): Router<ROUTABLE>; | ||
static no(reason?: string): Router<any>; | ||
route(routable: ROUTABLE): Observable<any>; | ||
route$(routable: ROUTABLE): Observable<boolean>; | ||
route(routable: ROUTABLE): Promise<boolean>; | ||
beforeDo(handler: Handler<ROUTABLE>): BeforeRouter<ROUTABLE>; | ||
@@ -38,2 +39,3 @@ afterDo(handler: Handler<ROUTABLE>): AfterRouter<ROUTABLE>; | ||
ifTrue(predicate: Predicate<ROUTABLE>): IfTrue<ROUTABLE>; | ||
route(routable: ROUTABLE, router: Router<ROUTABLE>): Promise<boolean>; | ||
} | ||
@@ -40,0 +42,0 @@ export declare class FirstRouter<ROUTABLE> extends Router<ROUTABLE> { |
@@ -32,4 +32,4 @@ "use strict"; | ||
var Router = /** @class */ (function () { | ||
function Router(getRoute) { | ||
this.getRoute = getRoute; | ||
function Router(getRoute$) { | ||
this.getRoute$ = getRoute$; | ||
} | ||
@@ -60,10 +60,16 @@ Router.actionRoute = function (action, score) { | ||
}; | ||
Router.prototype.route = function (routable) { | ||
Router.prototype.route$ = function (routable) { | ||
return this | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.do(function (route) { return Konsole_1.konsole.log("route: returned a route", route); }) | ||
.filter(function (route) { return route.type === 'action'; }) | ||
.flatMap(function (route) { return toObservable(route.action()); }) | ||
.do(function (_) { return Konsole_1.konsole.log("route: called action"); }); | ||
.flatMap(function (route) { return route.type === 'action' | ||
? toObservable(route.action()) | ||
.do(function (_) { return Konsole_1.konsole.log("route: called action"); }) | ||
.map(function (_) { return true; }) | ||
: rxjs_1.Observable.of(false); }); | ||
}; | ||
Router.prototype.route = function (routable) { | ||
return this.route$(routable) | ||
.toPromise(); | ||
}; | ||
Router.prototype.beforeDo = function (handler) { | ||
@@ -109,2 +115,5 @@ return new BeforeRouter(handler, this); | ||
}; | ||
Helpers.prototype.route = function (routable, router) { | ||
return router.route(routable); | ||
}; | ||
return Helpers; | ||
@@ -125,3 +134,3 @@ }()); | ||
return router | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.do(function (route) { return Konsole_1.konsole.log("first: router #" + i + " returned route", route); }); | ||
@@ -148,3 +157,3 @@ }) | ||
.takeWhile(function (_) { return bestRoute.score < 1; }) | ||
.concatMap(function (router) { return router.getRoute(routable); }) | ||
.concatMap(function (router) { return router.getRoute$(routable); }) | ||
.filter(function (route) { return route.type === 'action'; }) | ||
@@ -202,3 +211,3 @@ .defaultIfEmpty(Router.noRoute('tryInScoreOrder')) | ||
? getThenRouter(match.value) | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(function (route) { return route.type === 'action' | ||
@@ -208,3 +217,3 @@ ? routeWithCombinedScore(route, match.score) | ||
: getElseRouter(match.reason) | ||
.getRoute(routable); }); }) || this; | ||
.getRoute$(routable); }); }) || this; | ||
_this.matcher = matcher; | ||
@@ -225,3 +234,3 @@ _this.getThenRouter = getThenRouter; | ||
? getThenRouter(match.value) | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(function (route) { return route.type === 'action' | ||
@@ -341,3 +350,3 @@ ? routeWithCombinedScore(route, match.score) | ||
return _super.call(this, function (routable) { return router | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(function (route) { return route.type === 'action' | ||
@@ -354,3 +363,3 @@ ? __assign({}, route, { action: function () { return toObservable(beforeHandler(routable)) | ||
return _super.call(this, function (routable) { return router | ||
.getRoute(routable) | ||
.getRoute$(routable) | ||
.map(function (route) { return route.type === 'action' | ||
@@ -366,6 +375,6 @@ ? __assign({}, route, { action: function () { return toObservable(route.action()) | ||
function DefaultRouter(mainRouter, getDefaultRouter) { | ||
return _super.call(this, function (routable) { return mainRouter.getRoute(routable) | ||
return _super.call(this, function (routable) { return mainRouter.getRoute$(routable) | ||
.flatMap(function (route) { return route.type === 'action' | ||
? rxjs_1.Observable.of(route) | ||
: getDefaultRouter(route.reason).getRoute(routable); }); }) || this; | ||
: getDefaultRouter(route.reason).getRoute$(routable); }); }) || this; | ||
} | ||
@@ -372,0 +381,0 @@ return DefaultRouter; |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.15.3", | ||
"version": "0.15.8", | ||
"description": "rules-based app engine", | ||
@@ -24,3 +24,3 @@ "main": "dist/prague.js", | ||
"mocha": "^3.5.0", | ||
"typescript": "2.6.1" | ||
"typescript": "2.6.2" | ||
}, | ||
@@ -27,0 +27,0 @@ "dependencies": { |
@@ -7,3 +7,3 @@ "use strict"; | ||
const { toObservable, Router, toScore, routeWithCombinedScore, Helpers } = require('../dist/prague.js'); | ||
const { tryInOrder, tryInScoreOrder, ifMatches, ifTrue } = new Helpers(); | ||
const { tryInOrder, tryInScoreOrder, ifMatches, ifTrue, ifTry, route } = new Helpers(); | ||
const { Observable } = require('rxjs'); | ||
@@ -191,3 +191,3 @@ | ||
Router.do(m => { handled = m; }) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
@@ -212,3 +212,3 @@ expect(route.type).to.eql('action'); | ||
testRouter | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.flatMap(route => toObservable(route.action())) | ||
@@ -243,3 +243,3 @@ .subscribe(n => { | ||
Router.no() | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
@@ -256,3 +256,3 @@ expect(route.type).to.eql('no'); | ||
Router.no('reason') | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
@@ -268,7 +268,9 @@ expect(route.type).to.eql('no'); | ||
describe('Router.route', () => { | ||
it("should complete and never emit on Router.no", (done) => { | ||
describe('router.route', () => { | ||
it("should return false on Router.no", (done) => { | ||
Router.no() | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done); | ||
.route$(foo) | ||
.subscribe(t => { | ||
expect(t).to.be.false; | ||
}, passErr, done); | ||
}); | ||
@@ -284,7 +286,7 @@ | ||
testRouter | ||
.route(foo) | ||
.subscribe(n => { | ||
.route$(foo) | ||
.subscribe(t => { | ||
expect(t).to.be.true; | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -294,3 +296,3 @@ }); | ||
describe("router.beforeDo", () => { | ||
it("should complete and never emit with Router.no", (done) => { | ||
it("should return false with Router.no", (done) => { | ||
Router | ||
@@ -301,4 +303,4 @@ .no() | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
}); | ||
@@ -321,7 +323,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -331,3 +332,3 @@ }); | ||
describe("router.afterDo", () => { | ||
it("should complete and never emit with Router.no", (done) => { | ||
it("should return alse with Router.no", (done) => { | ||
Router | ||
@@ -338,5 +339,5 @@ .no() | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
}); | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
}); | ||
@@ -357,7 +358,6 @@ it("should run router's action and then 'after' router when router is supplied", (done) => { | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(handled).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -376,7 +376,6 @@ | ||
.defaultDo(throwErr) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -392,7 +391,6 @@ | ||
}) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(handled).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -410,7 +408,6 @@ }); | ||
.defaultTry(Router.do(throwErr)) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -428,7 +425,6 @@ }); | ||
.defaultTry(reason => Router.do(throwErr)) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -444,7 +440,6 @@ | ||
})) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(handled).to.eql('none'); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -454,9 +449,9 @@ }); | ||
describe('tryInOrder', () => { | ||
it('should complete and never emit on no routers', (done) => | ||
it('should return false on no routers', (done) => | ||
tryInOrder() | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it('should complete and never emit on only null/undefined routers', (done) => | ||
it('should return false on only null/undefined routers', (done) => | ||
tryInOrder( | ||
@@ -466,7 +461,7 @@ null, | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it('should complete and never emit on only unsuccessful and null/undefined routers', (done) => | ||
it('should return false on only unsuccessful and null/undefined routers', (done) => | ||
tryInOrder( | ||
@@ -477,12 +472,12 @@ Router.no(), | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it('should complete and never emit on no successful routers', (done) => { | ||
it('should return false on no successful routers', (done) => { | ||
tryInOrder( | ||
Router.no() | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
}); | ||
@@ -498,7 +493,7 @@ | ||
) | ||
.route(foo) | ||
.subscribe(n => { | ||
.route$(foo) | ||
.subscribe(t => { | ||
expect(t).to.be.true; | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -516,7 +511,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -533,7 +527,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -544,9 +537,9 @@ | ||
describe('tryInScoreOrder', () => { | ||
it('should complete and never emit on no routers', (done) => | ||
it('should return false on no routers', (done) => | ||
tryInScoreOrder() | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it('should complete and never emit on only null/undefined routers', (done) => | ||
it('should return false on only null/undefined routers', (done) => | ||
tryInScoreOrder( | ||
@@ -556,7 +549,7 @@ null, | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it('should complete and never emit on only unsuccessful and null/undefined routers', (done) => | ||
it('should return false on only unsuccessful and null/undefined routers', (done) => | ||
tryInScoreOrder( | ||
@@ -567,12 +560,12 @@ Router.no(), | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it('should complete and never emit on no successful routers', (done) => { | ||
it('should return false on no successful routers', (done) => { | ||
tryInScoreOrder( | ||
Router.no() | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
}); | ||
@@ -588,7 +581,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -606,7 +598,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -623,7 +614,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -640,7 +630,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -655,7 +644,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.eql('first'); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -670,7 +658,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.eql('second'); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -685,7 +672,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.eql('first'); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -700,7 +686,6 @@ | ||
) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.eql('first'); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -710,3 +695,3 @@ }); | ||
describe('Router.noop', () => { | ||
it("should execute the handler, complete, and never emit", (done) => { | ||
it("should execute the handler and return false", (done) => { | ||
let routed; | ||
@@ -719,8 +704,8 @@ | ||
) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, _ => { | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(n).to.be.false; | ||
expect(routed).to.be.true; | ||
done() | ||
}) | ||
}) | ||
}, passErr, done); | ||
}); | ||
}); | ||
@@ -738,30 +723,30 @@ | ||
describe('ifTrue', () => { | ||
it("should complete and never emit on false when 'else' router doesn't exist", (done) => | ||
it("should return false on false when 'else' router doesn't exist", (done) => | ||
ifTrue(m => false) | ||
.thenDo(throwErr) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it("should complete and never emit on false when 'else' router doesn't route", (done) => | ||
it("should return false on false when 'else' router doesn't route", (done) => | ||
ifTrue(m => false) | ||
.thenDo(throwErr) | ||
.elseTry(Router.no()) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it("should complete and never emit on true when 'if' router doesn't route and 'else' router doesn't exist", (done) => | ||
it("should return false on true when 'if' router doesn't route and 'else' router doesn't exist", (done) => | ||
ifTrue(m => true) | ||
.thenTry(Router.no()) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it("should complete and never emit on true when 'if' router doesn't route and 'else' router exists", (done) => | ||
it("should return false on true when 'if' router doesn't route and 'else' router exists", (done) => | ||
ifTrue(m => true) | ||
.thenTry(Router.no()) | ||
.elseDo(throwErr) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
@@ -776,7 +761,6 @@ | ||
}) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -792,7 +776,6 @@ | ||
.elseDo(throwErr) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -807,9 +790,8 @@ | ||
})) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
it("should route message to 'if' router on true predicate when 'else' router exists", (done) => { | ||
@@ -823,7 +805,6 @@ let routed; | ||
.elseDo(throwErr) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -839,7 +820,6 @@ | ||
}) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -855,3 +835,3 @@ | ||
})) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
@@ -866,7 +846,6 @@ expect(routed).to.be.true; | ||
.thenDo(m => {}) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(1); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -877,7 +856,6 @@ | ||
.thenTry(Router.do(() => {}, 0.25)) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(.25); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -889,7 +867,6 @@ | ||
.elseDo(m => {}) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(1); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -901,7 +878,6 @@ | ||
.elseTry(Router.do(_ => {}, .5)) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(.5); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -912,3 +888,3 @@ | ||
.thenDo(throwErr) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(throwErr, error => { | ||
@@ -922,3 +898,3 @@ done(); | ||
.thenDo(throwErr) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(throwErr, error => { | ||
@@ -932,7 +908,6 @@ done(); | ||
.thenDo(throwErr) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.reason).to.eql("none"); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -943,7 +918,6 @@ | ||
.thenDo(throwErr) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.reason).to.eql("whatevs"); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -956,3 +930,3 @@ | ||
.thenDo(m => { handled = true; }) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
@@ -962,4 +936,3 @@ route.action(); | ||
expect(route.score).to.eql(.5); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -972,7 +945,6 @@ | ||
.thenDo(throwErr) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.type).to.eql('no') | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -982,30 +954,30 @@ }); | ||
describe('ifMatches', () => { | ||
it("should complete and never emit on no match when 'else' router doesn't exist", (done) => | ||
it("should return false on no match when 'else' router doesn't exist", (done) => | ||
ifMatches(barIfFoo) | ||
.thenDo(throwErr) | ||
.route(notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(notFoo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it("should complete and never emit on no match when 'else' router doesn't exist", (done) => | ||
it("should return false on no match when 'else' router doesn't exist", (done) => | ||
ifMatches(barIfFoo) | ||
.thenTry(Router.do(throwErr)) | ||
.route(notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(notFoo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it("should complete and never emit on no match when 'else' router doesn't route", (done) => | ||
it("should return false on no match when 'else' router doesn't route", (done) => | ||
ifMatches(barIfFoo) | ||
.thenDo(throwErr) | ||
.elseTry(Router.no()) | ||
.route(notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(notFoo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
it("should complete and never emit on match when 'if' router doesn't route and 'else' router exists", (done) => | ||
it("should return false on match when 'if' router doesn't route and 'else' router exists", (done) => | ||
ifMatches(barIfFoo) | ||
.thenTry(Router.no()) | ||
.elseDo(throwErr) | ||
.route(foo) | ||
.subscribe(throwErr, passErr, done) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.false, passErr, done) | ||
); | ||
@@ -1020,7 +992,6 @@ | ||
}) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1036,7 +1007,6 @@ | ||
.elseDo(throwErr) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1052,7 +1022,6 @@ | ||
}) | ||
.route(notFoo) | ||
.route$(notFoo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1068,7 +1037,6 @@ | ||
})) | ||
.route(notFoo) | ||
.route$(notFoo) | ||
.subscribe(n => { | ||
expect(routed).to.be.true; | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1079,3 +1047,3 @@ | ||
.thenDo(m => {}) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
@@ -1090,7 +1058,6 @@ expect(route.score).to.eql(1); | ||
.thenDo(m => {}) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(.4); | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1104,7 +1071,6 @@ | ||
}) | ||
.route(foo) | ||
.route$(foo) | ||
.subscribe(_ => { | ||
expect(handled).to.eql('dog'); | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1115,7 +1081,6 @@ | ||
.thenTry(Router.do(() => {}, .25)) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(.25); | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1126,7 +1091,6 @@ | ||
.thenTry(Router.do(() => {}, .25)) | ||
.getRoute(foo) | ||
.getRoute$(foo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(.1); | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1138,7 +1102,6 @@ | ||
.elseTry(Router.do(() => {}, .5)) | ||
.getRoute(notFoo) | ||
.getRoute$(notFoo) | ||
.subscribe(route => { | ||
expect(route.score).to.eql(.5); | ||
done(); | ||
}) | ||
}, passErr, done); | ||
}); | ||
@@ -1153,7 +1116,6 @@ | ||
}) | ||
.route(foo) | ||
.subscribe(route => { | ||
.route$(foo) | ||
.subscribe(_ => { | ||
expect(handled.bar).to.eql("bar"); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -1168,7 +1130,6 @@ | ||
}) | ||
.route(foo) | ||
.subscribe(route => { | ||
.route$(foo) | ||
.subscribe(_ => { | ||
expect(handled.bar).to.eql("bar"); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -1183,7 +1144,6 @@ | ||
}) | ||
.route(foo) | ||
.subscribe(route => { | ||
.route$(foo) | ||
.subscribe(_ => { | ||
expect(handled.foobar).to.eql("foobar"); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
@@ -1198,9 +1158,57 @@ | ||
}) | ||
.route(foo) | ||
.subscribe(route => { | ||
.route$(foo) | ||
.subscribe(_ => { | ||
expect(handled.foobar).to.eql("bar"); | ||
done(); | ||
}); | ||
}, passErr, done); | ||
}); | ||
}); | ||
describe('inline Router', () => { | ||
it("should pass through no route", (done) => | ||
Router.do(c => | ||
Router.no() | ||
.route(c) | ||
) | ||
.route$(foo) | ||
.subscribe(t => expect(t).to.be.true, passErr, done) | ||
); | ||
it("should run handler", (done) => { | ||
let handled; | ||
Router.do(c => | ||
Router.do(c => { | ||
handled = true; | ||
}) | ||
.route(c) | ||
) | ||
.route$(foo) | ||
.subscribe(t => { | ||
expect(t).to.be.true; | ||
expect(handled).to.be.true; | ||
}, passErr, done); | ||
}); | ||
}); | ||
describe('route', () => { | ||
it("doesn't route NoRoute", done => { | ||
route(foo, Router.no()) | ||
.then(t => { | ||
expect(t).to.be.false; | ||
done(); | ||
}) | ||
}) | ||
it("routes ActionRoute", done => { | ||
let routed; | ||
route(foo, Router.do(c => { | ||
routed = true; | ||
})) | ||
.then(t => { | ||
expect(t).to.be.true; | ||
expect(routed).to.be.true; | ||
done(); | ||
}) | ||
}) | ||
}); |
Sorry, the diff of this file is not supported yet
133239
24
2368