Skip to content

Commit e3a6cc1

Browse files
authored
feat(seo): create injection tokens with factory (#3262)
1 parent a454214 commit e3a6cc1

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import {
2-
Provider,
3-
InjectionToken,
4-
} from '@angular/core';
1+
import { Provider } from '@angular/core';
52
import { Action } from '@ngrx/store';
63

4+
import { createMultiInjectionToken } from '@daffodil/core';
5+
76
import { DaffSeoCanonicalUrlUpdate } from '../../models/public_api';
87

9-
/**
10-
* A multi-provider injection token for providing canonical URL update logic.
11-
* `getData` will run in response to, and invoked with, the action specified.
12-
*/
13-
export const DAFF_SEO_CANONICAL_URL_UPDATES = new InjectionToken<DaffSeoCanonicalUrlUpdate[]>('DAFF_SEO_CANONICAL_URL_UPDATES', { factory: () => []});
8+
const {
9+
/**
10+
* A multi-provider injection token for providing canonical URL update logic.
11+
* `getData` will run in response to, and invoked with, the action specified.
12+
*/
13+
token: DAFF_SEO_CANONICAL_URL_UPDATES,
14+
provider,
15+
} = createMultiInjectionToken<DaffSeoCanonicalUrlUpdate>('DAFF_SEO_CANONICAL_URL_UPDATES');
1416

1517
/**
1618
* Provides canonical URL update logic.
@@ -26,9 +28,7 @@ export const DAFF_SEO_CANONICAL_URL_UPDATES = new InjectionToken<DaffSeoCanonica
2628
* ```
2729
*/
2830
export function daffProvideCanonicalUrlUpdates<T extends Action = Action>(...values: DaffSeoCanonicalUrlUpdate<T>[]): Provider[] {
29-
return values.map(value => ({
30-
provide: DAFF_SEO_CANONICAL_URL_UPDATES,
31-
useValue: value,
32-
multi: true,
33-
}));
31+
return provider(...values);
3432
}
33+
34+
export { DAFF_SEO_CANONICAL_URL_UPDATES };
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import {
2-
InjectionToken,
3-
Provider,
4-
} from '@angular/core';
1+
import { Provider } from '@angular/core';
52
import { Action } from '@ngrx/store';
63

4+
import { createMultiInjectionToken } from '@daffodil/core';
5+
76
import { DaffSeoMetaUpdate } from '../../models/public_api';
87

9-
/**
10-
* A multi-provider injection token for providing page meta update logic.
11-
* `getData` will run in response to, and invoked with, the action specified.
12-
*/
13-
export const DAFF_SEO_META_UPDATES = new InjectionToken<DaffSeoMetaUpdate[]>('DAFF_SEO_META_UPDATES', { factory: () => []});
8+
9+
const {
10+
/**
11+
* A multi-provider injection token for providing page meta update logic.
12+
* `getData` will run in response to, and invoked with, the action specified.
13+
*/
14+
token: DAFF_SEO_META_UPDATES,
15+
provider,
16+
} = createMultiInjectionToken<DaffSeoMetaUpdate>('DAFF_SEO_META_UPDATES');
1417

1518
/**
1619
* Provides page meta update logic.
@@ -26,9 +29,7 @@ export const DAFF_SEO_META_UPDATES = new InjectionToken<DaffSeoMetaUpdate[]>('DA
2629
* ```
2730
*/
2831
export function daffProvideMetaUpdates<T extends Action = Action>(...values: DaffSeoMetaUpdate<T>[]): Provider[] {
29-
return values.map(value => ({
30-
provide: DAFF_SEO_META_UPDATES,
31-
useValue: value,
32-
multi: true,
33-
}));
32+
return provider(...values);
3433
}
34+
35+
export { DAFF_SEO_META_UPDATES };
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import {
2-
Provider,
3-
InjectionToken,
4-
} from '@angular/core';
1+
import { Provider } from '@angular/core';
52
import { Action } from '@ngrx/store';
63

4+
import { createMultiInjectionToken } from '@daffodil/core';
5+
76
import { DaffSeoTitleUpdate } from '../../models/public_api';
87

9-
/**
10-
* A multi-provider injection token for providing canonical URL update logic.
11-
* `getData` will run in response to, and invoked with, the action specified.
12-
*/
13-
export const DAFF_SEO_TITLE_UPDATES = new InjectionToken<DaffSeoTitleUpdate[]>('DAFF_SEO_TITLE_UPDATES', { factory: () => []});
8+
const {
9+
/**
10+
* A multi-provider injection token for providing canonical URL update logic.
11+
* `getData` will run in response to, and invoked with, the action specified.
12+
*/
13+
token: DAFF_SEO_TITLE_UPDATES,
14+
provider,
15+
} = createMultiInjectionToken<DaffSeoTitleUpdate>('DAFF_SEO_TITLE_UPDATES');
1416

1517
/**
1618
* Provides canonical URL update logic.
@@ -26,9 +28,7 @@ export const DAFF_SEO_TITLE_UPDATES = new InjectionToken<DaffSeoTitleUpdate[]>('
2628
* ```
2729
*/
2830
export function daffProvideTitleUpdates<T extends Action = Action>(...values: DaffSeoTitleUpdate<T>[]): Provider[] {
29-
return values.map(value => ({
30-
provide: DAFF_SEO_TITLE_UPDATES,
31-
useValue: value,
32-
multi: true,
33-
}));
31+
return provider(...values);
3432
}
33+
34+
export { DAFF_SEO_TITLE_UPDATES };

0 commit comments

Comments
 (0)