festure + improvement - matchPatch operator + matchType operator
MODIFY
example/controllers.ts
example/controllers.ts
-import { filter, map } from 'rxjs/operators';
-import { Effect, HttpStatus, ofType } from '../src';
+import { map } from 'rxjs/operators';
+import { Effect, HttpStatus, matchPath, matchType } from '../src';
export const root$: Effect = request$ => request$
.pipe(
- filter(req => req.url === '/'),
- ofType('GET'),
+ matchPath('/'),
+ matchType('GET'),
map(req => ({
status: HttpStatus.OK,
body: { data: `API root @ ${req.url}` },
@@ -13,8 +13,8 @@ export const root$: Effect = request$ => request$
export const hello$: Effect = request$ => request$
.pipe(
- filter(req => req.url === '/hello'),
- ofType('POST'),
+ matchPath('/hello'),
+ matchType('POST'),
map(req => ({
status: HttpStatus.OK,
body: { data: `Hello, ${req.body.data}! @ ${req.url}` },

MODIFY
src/index.ts
src/index.ts
@@ -2,6 +2,7 @@ export * from './effects/effects.interface';
export * from './middlewares/bodyParser.middleware';
export * from './middlewares/error.middleware';
export * from './middlewares/logger.middleware';
-export * from './operators/ofType.operator';
+export * from './operators/matchType.operator';
+export * from './operators/matchPath.operator';
export * from './http.interface';
export * from './http.listener';

ADD
src/operators/matchPath.operator.ts
+import { Observable } from 'rxjs';
+import { filter } from 'rxjs/operators';
+import { HttpRequest } from '../http.interface';
+
+export const matchPath = (path: string) => (source$: Observable<HttpRequest>) =>
+ source$.pipe(
+ filter(req => req.url === path)
+ );

RENAME
src/operators/ofType.operator.ts
src/operators/matchType.operator.ts
@@ -2,7 +2,7 @@ import { Observable } from 'rxjs';
import { filter } from 'rxjs/operators';
import { HttpMethod, HttpRequest } from '../http.interface';
-export const ofType = (httpMethodType: HttpMethod) => (source$: Observable<HttpRequest>) =>
+export const matchType = (method: HttpMethod) => (source$: Observable<HttpRequest>) =>
source$.pipe(
- filter(req => req.method === httpMethodType)
+ filter(req => req.method === method)
);

festure + improvement - matchPatch operator + matchType operator