|
1 |
| -import { |
2 |
| - InjectionToken, |
3 |
| - ValueProvider, |
4 |
| -} from '@angular/core'; |
5 | 1 | import { ActivatedRouteSnapshot } from '@angular/router';
|
6 | 2 |
|
| 3 | +import { createMultiInjectionToken } from '@daffodil/core'; |
7 | 4 | import { DaffSearchDriverOptions } from '@daffodil/search/driver';
|
8 | 5 |
|
9 | 6 | export type DaffSearchRoutingOptionBuilder<T extends DaffSearchDriverOptions = DaffSearchDriverOptions> = (route: ActivatedRouteSnapshot) => T;
|
10 | 7 |
|
11 |
| -/** |
12 |
| - * A multi-provider injection token for search option builders. |
13 |
| - * These builders are called with the requested route during the resolve step |
14 |
| - * and return options to pass to the search driver. |
15 |
| - */ |
16 |
| -export const DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS = new InjectionToken<DaffSearchRoutingOptionBuilder[]>( |
17 |
| - 'DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS', |
18 |
| - { factory: () => []}, |
19 |
| -); |
| 8 | +export const { |
| 9 | + /** |
| 10 | + * A multi-provider injection token for search option builders. |
| 11 | + * These builders are called with the requested route during the resolve step |
| 12 | + * and return options to pass to the search driver. |
| 13 | + */ |
| 14 | + token: DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS, |
20 | 15 |
|
21 |
| -/** |
22 |
| - * Provides search option builders for the routing layer. |
23 |
| - * |
24 |
| - * See {@link DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS}. |
25 |
| - * |
26 |
| - * ```ts |
27 |
| - * providers: [ |
28 |
| - * ...daffProvideSearchRoutingOptionBuilders( |
29 |
| - * route => ({ |
30 |
| - * limit: route.queryParams.limit |
31 |
| - * }) |
32 |
| - * ) |
33 |
| - * ] |
34 |
| - * ``` |
35 |
| - */ |
36 |
| -export function daffProvideSearchRoutingOptionBuilders(...builders: DaffSearchRoutingOptionBuilder[]): ValueProvider[] { |
37 |
| - return builders.map(builder => ({ |
38 |
| - provide: DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS, |
39 |
| - useValue: builder, |
40 |
| - multi: true, |
41 |
| - })); |
42 |
| -} |
| 16 | + /** |
| 17 | + * Provides search option builders for the routing layer. |
| 18 | + * |
| 19 | + * See {@link DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS}. |
| 20 | + * |
| 21 | + * ```ts |
| 22 | + * providers: [ |
| 23 | + * ...daffProvideSearchRoutingOptionBuilders( |
| 24 | + * route => ({ |
| 25 | + * limit: route.queryParams.limit |
| 26 | + * }) |
| 27 | + * ) |
| 28 | + * ] |
| 29 | + * ``` |
| 30 | + */ |
| 31 | + provider: daffProvideSearchRoutingOptionBuilders, |
| 32 | +} = createMultiInjectionToken<DaffSearchRoutingOptionBuilder>('DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS'); |
0 commit comments