From c3ea0bf4471ae4639cb928852280f72741e35362 Mon Sep 17 00:00:00 2001 From: griest024 Date: Mon, 14 Oct 2024 15:37:39 -0400 Subject: [PATCH] feat(analytics): create injection tokens with factory (#3221) --- libs/analytics/package.json | 3 +++ libs/analytics/src/lib/analytics-tracker.ts | 15 ++++++++------- libs/analytics/src/lib/config/config.ts | 20 ++++++++++++-------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/libs/analytics/package.json b/libs/analytics/package.json index c1b0c9cd63..96aa922566 100644 --- a/libs/analytics/package.json +++ b/libs/analytics/package.json @@ -31,5 +31,8 @@ "rxjs": "0.0.0-PLACEHOLDER", "@ngrx/store": "0.0.0-PLACEHOLDER", "@ngrx/effects": "0.0.0-PLACEHOLDER" + }, + "devDependencies": { + "@daffodil/core": "0.0.0-PLACEHOLDER" } } diff --git a/libs/analytics/src/lib/analytics-tracker.ts b/libs/analytics/src/lib/analytics-tracker.ts index edb467bddd..4100be8020 100644 --- a/libs/analytics/src/lib/analytics-tracker.ts +++ b/libs/analytics/src/lib/analytics-tracker.ts @@ -1,6 +1,7 @@ -import { InjectionToken } from '@angular/core'; import { Observable } from 'rxjs'; +import { createMultiInjectionToken } from '@daffodil/core'; + import { DaffAnalyticsEvent } from './event/event'; /** @@ -39,9 +40,9 @@ export type DaffAnalyticsTrackerFunction = (event: DaffAnalyticsEvent) => Observ */ export type DaffAnalyticsTracker = DaffAnalyticsTrackerFunction | DaffAnalyticsTrackerClass; -/** - * An injection token representing all of the different analytics trackers. - */ -export const DaffAnalyticsServices = new InjectionToken('DaffAnalyticsServices', { - factory: () => [], -}); +export const { + /** + * An injection token representing all of the different analytics trackers. + */ + token: DaffAnalyticsServices, +} = createMultiInjectionToken('DaffAnalyticsServices'); diff --git a/libs/analytics/src/lib/config/config.ts b/libs/analytics/src/lib/config/config.ts index 7bcf8a94fc..b05fdc3879 100644 --- a/libs/analytics/src/lib/config/config.ts +++ b/libs/analytics/src/lib/config/config.ts @@ -1,4 +1,4 @@ -import { InjectionToken } from '@angular/core'; +import { createConfigInjectionToken } from '@daffodil/core'; /** * The default analytics configuration. We intentionally do not track @@ -20,10 +20,14 @@ export interface DaffAnalyticsConfigInterface { analyzableActions: string[]; } -/** - * Allows you to provide configuration to the `@daffodil/analytics` package. - */ -export const DaffAnalyticsConfig = new InjectionToken('DaffAnalyticsConfig', { - providedIn: 'root', - factory: () => defaultConfig, -}); +export const { + /** + * Allows you to provide configuration to the `@daffodil/analytics` package. + */ + token: DaffAnalyticsConfig, + provider: daffProvideAnalyticsConfig, +} = createConfigInjectionToken( + defaultConfig, + 'DaffAnalyticsConfig', + { providedIn: 'root' }, +);