Skip to content

Commit c3ea0bf

Browse files
authored
feat(analytics): create injection tokens with factory (#3221)
1 parent 2fbd482 commit c3ea0bf

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

libs/analytics/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
"rxjs": "0.0.0-PLACEHOLDER",
3232
"@ngrx/store": "0.0.0-PLACEHOLDER",
3333
"@ngrx/effects": "0.0.0-PLACEHOLDER"
34+
},
35+
"devDependencies": {
36+
"@daffodil/core": "0.0.0-PLACEHOLDER"
3437
}
3538
}

libs/analytics/src/lib/analytics-tracker.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { InjectionToken } from '@angular/core';
21
import { Observable } from 'rxjs';
32

3+
import { createMultiInjectionToken } from '@daffodil/core';
4+
45
import { DaffAnalyticsEvent } from './event/event';
56

67
/**
@@ -39,9 +40,9 @@ export type DaffAnalyticsTrackerFunction = (event: DaffAnalyticsEvent) => Observ
3940
*/
4041
export type DaffAnalyticsTracker = DaffAnalyticsTrackerFunction | DaffAnalyticsTrackerClass;
4142

42-
/**
43-
* An injection token representing all of the different analytics trackers.
44-
*/
45-
export const DaffAnalyticsServices = new InjectionToken<DaffAnalyticsTracker[]>('DaffAnalyticsServices', {
46-
factory: () => [],
47-
});
43+
export const {
44+
/**
45+
* An injection token representing all of the different analytics trackers.
46+
*/
47+
token: DaffAnalyticsServices,
48+
} = createMultiInjectionToken<DaffAnalyticsTracker>('DaffAnalyticsServices');

libs/analytics/src/lib/config/config.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InjectionToken } from '@angular/core';
1+
import { createConfigInjectionToken } from '@daffodil/core';
22

33
/**
44
* The default analytics configuration. We intentionally do not track
@@ -20,10 +20,14 @@ export interface DaffAnalyticsConfigInterface {
2020
analyzableActions: string[];
2121
}
2222

23-
/**
24-
* Allows you to provide configuration to the `@daffodil/analytics` package.
25-
*/
26-
export const DaffAnalyticsConfig = new InjectionToken<DaffAnalyticsConfigInterface>('DaffAnalyticsConfig', {
27-
providedIn: 'root',
28-
factory: () => defaultConfig,
29-
});
23+
export const {
24+
/**
25+
* Allows you to provide configuration to the `@daffodil/analytics` package.
26+
*/
27+
token: DaffAnalyticsConfig,
28+
provider: daffProvideAnalyticsConfig,
29+
} = createConfigInjectionToken(
30+
defaultConfig,
31+
'DaffAnalyticsConfig',
32+
{ providedIn: 'root' },
33+
);

0 commit comments

Comments
 (0)