prague-fluent
Advanced tools
Comparing version 0.16.3 to 0.16.4
@@ -26,8 +26,9 @@ import { Matcher, Observableable, Predicate, Router } from './FluentRouter'; | ||
export declare class Helpers<ROUTABLE> { | ||
tryInOrder(...routers: Router<ROUTABLE>[]): Router<ROUTABLE>; | ||
tryInScoreOrder(...routers: Router<ROUTABLE>[]): Router<ROUTABLE>; | ||
tryInOrder(...getRouters: (Router<ROUTABLE> | ((routable: ROUTABLE) => Observableable<Router<ROUTABLE>>))[]): Router<ROUTABLE>; | ||
tryInScoreOrder(...getRouters: (Router<ROUTABLE> | ((routable: ROUTABLE) => Observableable<Router<ROUTABLE>>))[]): Router<ROUTABLE>; | ||
ifMatches<VALUE>(matcher: Matcher<ROUTABLE, VALUE>): IfMatchesFluent<ROUTABLE, VALUE>; | ||
ifTrue(predicate: Predicate<ROUTABLE>): IfTrueFluent<ROUTABLE>; | ||
route(routable: ROUTABLE, router: Router<ROUTABLE>): Promise<boolean>; | ||
trySwitch(getKey: (routable: ROUTABLE) => Observableable<string>, mapKeyToRouter: Record<string, Router<ROUTABLE>>): Router<ROUTABLE>; | ||
trySwitch(getKey: (routable: ROUTABLE) => Observableable<string>, mapKeyToGetRouter: Record<string, Router<ROUTABLE>>): Router<ROUTABLE>; | ||
trySwitch(getKey: (routable: ROUTABLE) => Observableable<string>, getMapKeyToGetRouter: (routable: ROUTABLE) => Observableable<Record<string, Router<ROUTABLE>>>): Router<ROUTABLE>; | ||
} |
@@ -86,14 +86,18 @@ "use strict"; | ||
Helpers.prototype.tryInOrder = function () { | ||
var routers = []; | ||
var getRouters = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
routers[_i] = arguments[_i]; | ||
getRouters[_i] = arguments[_i]; | ||
} | ||
return new FluentRouter_1.Router(FluentRouter_1.Router.getRouteFirst$.apply(FluentRouter_1.Router, routers)); | ||
return new FluentRouter_1.Router(FluentRouter_1.Router.getRouteFirst$.apply(FluentRouter_1.Router, getRouters.map(function (getRouter) { return typeof (getRouter) === 'function' | ||
? getRouter | ||
: function (routable) { return getRouter; }; }))); | ||
}; | ||
Helpers.prototype.tryInScoreOrder = function () { | ||
var routers = []; | ||
var getRouters = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
routers[_i] = arguments[_i]; | ||
getRouters[_i] = arguments[_i]; | ||
} | ||
return new FluentRouter_1.Router(FluentRouter_1.Router.getRouteBest$.apply(FluentRouter_1.Router, routers)); | ||
return new FluentRouter_1.Router(FluentRouter_1.Router.getRouteBest$.apply(FluentRouter_1.Router, getRouters.map(function (getRouter) { return typeof (getRouter) === 'function' | ||
? getRouter | ||
: function (routable) { return getRouter; }; }))); | ||
}; | ||
@@ -109,4 +113,6 @@ Helpers.prototype.ifMatches = function (matcher) { | ||
}; | ||
Helpers.prototype.trySwitch = function (getKey, mapKeyToRouter) { | ||
return new FluentRouter_1.Router(FluentRouter_1.Router.getRouteSwitch$(getKey, mapKeyToRouter)); | ||
Helpers.prototype.trySwitch = function (getKey, arg) { | ||
return new FluentRouter_1.Router(FluentRouter_1.Router.getRouteSwitch$(getKey, typeof (arg) === 'function' | ||
? arg | ||
: function (routable) { return arg; })); | ||
}; | ||
@@ -113,0 +119,0 @@ return Helpers; |
@@ -17,3 +17,2 @@ "use strict"; | ||
var prague_1 = require("prague"); | ||
var rxjs_1 = require("rxjs"); | ||
__export(require("prague")); | ||
@@ -35,13 +34,6 @@ var FluentRouter = /** @class */ (function (_super) { | ||
FluentRouter.prototype.route$ = function (routable) { | ||
return this | ||
._getRoute$(routable) | ||
.do(function (route) { return prague_1.konsole.log("route: returned a route", route); }) | ||
.flatMap(function (route) { return route.type === 'action' | ||
? prague_1.toObservable(route.action()) | ||
.do(function (_) { return prague_1.konsole.log("route: called action"); }) | ||
.map(function (_) { return true; }) | ||
: rxjs_1.Observable.of(false); }); | ||
return prague_1.Router.route$(routable, this); | ||
}; | ||
FluentRouter.prototype.route = function (routable) { | ||
return this.route$(routable) | ||
return prague_1.Router.route$(routable, this) | ||
.toPromise(); | ||
@@ -48,0 +40,0 @@ }; |
{ | ||
"name": "prague-fluent", | ||
"version": "0.16.3", | ||
"version": "0.16.4", | ||
"description": "fluent API for Prague", | ||
@@ -21,5 +21,5 @@ "main": "dist/fluent.js", | ||
"dependencies": { | ||
"prague": "^0.16.1", | ||
"prague": "^0.16.3", | ||
"rxjs": "5.5.2" | ||
} | ||
} |
@@ -19,3 +19,5 @@ import { konsole, Matcher, Observableable, toObservable, Predicate, Handler, GetRoute$, Router } from './FluentRouter'; | ||
elseTry(elseRouter: Router<ROUTABLE>): Router<ROUTABLE>; | ||
elseTry(getElseRouter: (routable: ROUTABLE, reason: string) => Router<ROUTABLE>): Router<ROUTABLE>; | ||
elseTry(arg: Router<ROUTABLE> | ((routable: ROUTABLE, reason: string) => Router<ROUTABLE>)) { | ||
@@ -36,5 +38,9 @@ return new Router(Router.getRouteIfMatches$(this.matcher, this.getThenRouter, typeof(arg) === 'function' | ||
and (predicate: (value: VALUE) => IfTrueFluent<ROUTABLE>): IfMatchesFluent<ROUTABLE, VALUE>; | ||
and (predicate: IfTrueFluent<ROUTABLE>): IfMatchesFluent<ROUTABLE, VALUE>; | ||
and <TRANSFORMRESULT> (recognizer: (value: VALUE) => IfMatchesFluent<ROUTABLE, TRANSFORMRESULT>): IfMatchesFluent<ROUTABLE, TRANSFORMRESULT>; | ||
and <TRANSFORMRESULT> (recognizer: IfMatchesFluent<ROUTABLE, TRANSFORMRESULT>): IfMatchesFluent<ROUTABLE, TRANSFORMRESULT>; | ||
and <TRANSFORMRESULT> (arg) { | ||
@@ -73,3 +79,5 @@ const recognizer = typeof(arg) === 'function' | ||
thenTry(router: Router<ROUTABLE>): IfMatchesThen<ROUTABLE, VALUE>; | ||
thenTry(getRouter: (routable: ROUTABLE, value: VALUE) => Router<ROUTABLE>): IfMatchesThen<ROUTABLE, VALUE>; | ||
thenTry(arg: Router<ROUTABLE> | ((routable: ROUTABLE, value: VALUE) => Router<ROUTABLE>)) { | ||
@@ -92,9 +100,19 @@ return new IfMatchesThen(this.matcher, typeof arg === 'function' | ||
export class Helpers <ROUTABLE> { | ||
tryInOrder (... routers: Router<ROUTABLE>[]) { | ||
return new Router(Router.getRouteFirst$(... routers)); | ||
tryInOrder ( | ||
... getRouters: (Router<ROUTABLE> | ((routable: ROUTABLE) => Observableable<Router<ROUTABLE>>))[] | ||
) { | ||
return new Router(Router.getRouteFirst$(... getRouters.map(getRouter => typeof(getRouter) === 'function' | ||
? getRouter | ||
: (routable: ROUTABLE) => getRouter | ||
))); | ||
} | ||
tryInScoreOrder (... routers: Router<ROUTABLE>[]) { | ||
return new Router(Router.getRouteBest$(... routers)); | ||
} | ||
tryInScoreOrder ( | ||
... getRouters: (Router<ROUTABLE> | ((routable: ROUTABLE) => Observableable<Router<ROUTABLE>>))[] | ||
) { | ||
return new Router(Router.getRouteBest$(... getRouters.map(getRouter => typeof(getRouter) === 'function' | ||
? getRouter | ||
: (routable: ROUTABLE) => getRouter | ||
))); | ||
} | ||
@@ -115,7 +133,20 @@ ifMatches <VALUE>(matcher: Matcher<ROUTABLE, VALUE>) { | ||
getKey: (routable: ROUTABLE) => Observableable<string>, | ||
mapKeyToRouter: Record<string, Router<ROUTABLE>> | ||
) { | ||
return new Router(Router.getRouteSwitch$(getKey, mapKeyToRouter)); | ||
mapKeyToGetRouter: Record<string, Router<ROUTABLE>> | ||
): Router<ROUTABLE>; | ||
trySwitch( | ||
getKey: (routable: ROUTABLE) => Observableable<string>, | ||
getMapKeyToGetRouter: (routable: ROUTABLE) => Observableable<Record<string, Router<ROUTABLE>>> | ||
): Router<ROUTABLE>; | ||
trySwitch( | ||
getKey: (routable: ROUTABLE) => Observableable<string>, | ||
arg: Record<string, Router<ROUTABLE>> | ((routable: ROUTABLE) => Observableable<Record<string, Router<ROUTABLE>>>) | ||
): Router<ROUTABLE> { | ||
return new Router(Router.getRouteSwitch$(getKey, typeof(arg) === 'function' | ||
? arg | ||
: (routable: ROUTABLE) => arg | ||
)); | ||
} | ||
} | ||
@@ -27,15 +27,7 @@ import { konsole, Router, Matcher, Observableable, toObservable, Predicate, Handler, GetRoute$ } from 'prague'; | ||
route$ (routable: ROUTABLE) { | ||
return this | ||
._getRoute$(routable) | ||
.do(route => konsole.log("route: returned a route", route)) | ||
.flatMap(route => route.type === 'action' | ||
? toObservable(route.action()) | ||
.do(_ => konsole.log("route: called action")) | ||
.map(_ => true) | ||
: Observable.of(false) | ||
); | ||
return Router.route$(routable, this); | ||
} | ||
route (routable: ROUTABLE) { | ||
return this.route$(routable) | ||
return Router.route$(routable, this) | ||
.toPromise(); | ||
@@ -42,0 +34,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26084
10
390
1
Updatedprague@^0.16.3