imp(core): meta field for RouteEffect
MODIFY
packages/core/src/router/router.interface.ts
packages/core/src/router/router.interface.ts
@@ -7,6 +7,7 @@ export interface RouteEffect<T extends HttpRequest = HttpRequest> {
method: HttpMethod;
effect: HttpEffect<T, HttpEffectResponse>;
middleware?: HttpMiddlewareEffect;
+ meta?: any;
}
export interface RouteEffectGroup {

MODIFY
packages/core/src/router/router.ixbuilder.ts
packages/core/src/router/router.ixbuilder.ts
@@ -9,6 +9,7 @@ type PathApplied = 'PathApplied';
type TypeApplied = 'TypeApplied';
type MiddlewareApplied = 'MiddlewareApplied';
type EffectApplied = 'EffectApplied';
+type MetaApplied = 'MetaApplied';
type RouteEffectSpec = Partial<RouteEffect>;
@@ -143,4 +144,10 @@ const use = (middleware: HttpMiddlewareEffect) => ichain((spec: RouteEffectSpec)
const useEffect = (effect: HttpEffect) => ichain((spec: RouteEffectSpec) =>
new IxRouteBuilder<TypeApplied | MiddlewareApplied, EffectApplied, RouteEffectSpec>({ ...spec, effect }));
-export const r = { matchPath, matchType, use, useEffect, pipe };
+const applyMeta = (meta: Record<string, any>) => ichain((spec: RouteEffectSpec) =>
+ new IxRouteBuilder<EffectApplied | MetaApplied, MetaApplied, RouteEffectSpec>({
+ ...spec,
+ meta: { ...spec.meta, ...meta },
+ }));
+
+export const r = { matchPath, matchType, use, useEffect, applyMeta, pipe };

MODIFY
packages/core/src/router/specs/route.ixbuilder.spec.ts
packages/core/src/router/specs/route.ixbuilder.spec.ts
@@ -2,7 +2,23 @@ import { r } from '../router.ixbuilder';
import { HttpMiddlewareEffect, HttpEffect } from '../../effects/http-effects.interface';
describe('#IxRouteBuilder', () => {
- test('builds EffectRoute with all ingridients', () => {
+ test('builds EffectRoute with required ingredients', () => {
+ const e$: HttpEffect = req$ => req$;
+
+ const route = r.pipe(
+ r.matchPath('/'),
+ r.matchType('GET'),
+ r.useEffect(e$),
+ );
+
+ expect(route.path).toEqual('/');
+ expect(route.method).toEqual('GET');
+ expect(route.effect).toEqual(e$);
+ expect(route.middleware).toBeUndefined();
+ expect(route.effect).toBeInstanceOf(Function);
+ });
+
+ test('builds EffectRoute with chain of middlewares applied', () => {
const m$: HttpMiddlewareEffect = req$ => req$;
const e$: HttpEffect = req$ => req$;
@@ -20,21 +36,23 @@ describe('#IxRouteBuilder', () => {
expect(route.effect).toEqual(e$);
expect(route.middleware).toBeInstanceOf(Function);
expect(route.effect).toBeInstanceOf(Function);
+ expect(route.meta).toBeUndefined();
});
- test('builds EffectRoute without middleware', () => {
+ test('builds EffectRoute with chain of meta attributes applied', () => {
const e$: HttpEffect = req$ => req$;
const route = r.pipe(
r.matchPath('/'),
r.matchType('GET'),
r.useEffect(e$),
+ r.applyMeta({ test1: 1 }),
+ r.applyMeta({ test2: 2 }),
);
expect(route.path).toEqual('/');
expect(route.method).toEqual('GET');
expect(route.effect).toEqual(e$);
- expect(route.middleware).toBeUndefined();
- expect(route.effect).toBeInstanceOf(Function);
+ expect(route.meta).toEqual({ test1: 1, test2: 2 });
});
});

imp(core): meta field for RouteEffect