Skip to content

Commit 35738d4

Browse files
authored
feat(router): add generic to router data (#2951)
1 parent d907c13 commit 35738d4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libs/router/src/data/helpers/collect-data.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { collect } from '@daffodil/core';
99
* Collects data defined in the entire tree of routes.
1010
* Shallow merges data, preferring fields of more deeply nested routes.
1111
*/
12-
export const daffRouterDataCollect = (route: ActivatedRouteSnapshot): Route['data'] => {
12+
export const daffRouterDataCollect = <T extends Route['data'] = Route['data']>(route: ActivatedRouteSnapshot): T => {
1313
const ary = collect(route, (r) => r.children);
1414
const ret = ary.reduce(
1515
(acc, r) => r.data
@@ -18,7 +18,7 @@ export const daffRouterDataCollect = (route: ActivatedRouteSnapshot): Route['dat
1818
...r.data,
1919
}
2020
: acc,
21-
{},
21+
<T>{},
2222
);
2323
return ret;
2424
};

libs/router/src/data/service/data.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import { daffRouterDataCollect } from '../helpers/collect-data';
1717
@Injectable({
1818
providedIn: 'root',
1919
})
20-
export class DaffRouterDataService {
20+
export class DaffRouterDataService<T extends Route['data'] = Route['data']> {
2121
/**
2222
* A collection of all the route data defined in any part of the currently activated route's tree.
2323
* Child route's data takes precendence over parent data.
2424
*/
25-
public data$: Observable<Route['data']>;
25+
public data$: Observable<T>;
2626

2727
constructor(
2828
private route: ActivatedRoute,
@@ -46,7 +46,7 @@ export class DaffRouterDataService {
4646
this.route.url,
4747
).pipe(
4848
map(() => this.route.snapshot),
49-
map(daffRouterDataCollect),
49+
map(daffRouterDataCollect<T>),
5050
);
5151
}
5252
}

0 commit comments

Comments
 (0)