Skip to content

Commit

Permalink
feat(analytics): create injection tokens with factory (#3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Oct 14, 2024
1 parent 2fbd482 commit c3ea0bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
3 changes: 3 additions & 0 deletions libs/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
15 changes: 8 additions & 7 deletions libs/analytics/src/lib/analytics-tracker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs';

import { createMultiInjectionToken } from '@daffodil/core';

import { DaffAnalyticsEvent } from './event/event';

/**
Expand Down Expand Up @@ -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<DaffAnalyticsTracker[]>('DaffAnalyticsServices', {
factory: () => [],
});
export const {
/**
* An injection token representing all of the different analytics trackers.
*/
token: DaffAnalyticsServices,
} = createMultiInjectionToken<DaffAnalyticsTracker>('DaffAnalyticsServices');
20 changes: 12 additions & 8 deletions libs/analytics/src/lib/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InjectionToken } from '@angular/core';
import { createConfigInjectionToken } from '@daffodil/core';

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

/**
* Allows you to provide configuration to the `@daffodil/analytics` package.
*/
export const DaffAnalyticsConfig = new InjectionToken<DaffAnalyticsConfigInterface>('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' },
);

0 comments on commit c3ea0bf

Please sign in to comment.