Skip to content

Commit

Permalink
feat(contact): create injection tokens with factory (#3239)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Oct 14, 2024
1 parent 2a9a32d commit 0ae0282
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InjectionToken } from '@angular/core';

import { createSingleInjectionToken } from '@daffodil/core';
import { DaffHubspotConfig } from '@daffodil/driver/hubspot';

export const DaffContactConfigToken = new InjectionToken<DaffHubspotConfig>(
'DaffContactConfig',
);
export const {
token: DaffContactConfigToken,
provider: daffProvideContactConfigToken,
} = createSingleInjectionToken<DaffHubspotConfig>('DaffContactConfig');
18 changes: 11 additions & 7 deletions libs/contact/driver/hubspot/src/token/hubspot-forms.token.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { DOCUMENT } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import {
inject,
InjectionToken,
} from '@angular/core';
import { inject } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Router } from '@angular/router';

import { createSingleInjectionToken } from '@daffodil/core';
import {
DaffHubspotFormsService,
daffHubspotFormsServiceFactory,
} from '@daffodil/driver/hubspot';

import { DaffContactConfigToken } from '../config/contact-config.interface';

export const DAFF_CONTACT_HUBSPOT_FORMS_TOKEN = new InjectionToken<DaffHubspotFormsService>('DAFF_CONTACT_HUBSPOT_FORMS_TOKEN',
export const {
token: DAFF_CONTACT_HUBSPOT_FORMS_TOKEN,
provider: daffProvideContactHubspotFormsToken,
} = createSingleInjectionToken<DaffHubspotFormsService>(
'DAFF_CONTACT_HUBSPOT_FORMS_TOKEN',
{
providedIn: 'root', factory: () => daffHubspotFormsServiceFactory(
providedIn: 'root',
factory: () => daffHubspotFormsServiceFactory(
inject(HttpClient),
inject(DOCUMENT),
inject(Router),
inject(Title),
inject(DaffContactConfigToken),
),
});
},
);
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs';

export const DaffContactDriver = new InjectionToken<DaffContactServiceInterface<any, any>>('DaffContactDriver');
import { createSingleInjectionToken } from '@daffodil/core';

export const {
token: DaffContactDriver,
provider: daffProvideContactDriver,
} = createSingleInjectionToken<DaffContactServiceInterface<any, any>>('DaffContactDriver');
export interface DaffContactServiceInterface<T, V> {
send(payload: T): Observable<V>;
}
16 changes: 9 additions & 7 deletions libs/contact/src/injection-tokens/error-matcher.token.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { InjectionToken } from '@angular/core';

import { createSingleInjectionToken } from '@daffodil/core';
import { daffTransformErrorToStateError } from '@daffodil/core/state';

/**
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state.
* Can be used to further refine Daffodil errors into more specific app errors.
*/
export const DAFF_CONTACT_ERROR_MATCHER = new InjectionToken<typeof daffTransformErrorToStateError>(
export const {
/**
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state.
* Can be used to further refine Daffodil errors into more specific app errors.
*/
token: DAFF_CONTACT_ERROR_MATCHER,
provider: daffProvideContactErrorMatcher,
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>(
'DAFF_CONTACT_ERROR_MATCHER',
{ factory: () => daffTransformErrorToStateError },
);
2 changes: 1 addition & 1 deletion libs/contact/src/injection-tokens/public_api.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DAFF_CONTACT_ERROR_MATCHER } from './error-matcher.token';
export * from './error-matcher.token';

0 comments on commit 0ae0282

Please sign in to comment.