-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(customer-payment): create injection tokens with factory (#3243)
- Loading branch information
Showing
7 changed files
with
85 additions
and
94 deletions.
There are no files selected for viewing
17 changes: 11 additions & 6 deletions
17
libs/customer-payment/driver/src/interfaces/payment-service.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 15 additions & 24 deletions
39
libs/customer-payment/state/src/injection-tokens/available-transforms.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
import { | ||
InjectionToken, | ||
ValueProvider, | ||
} from '@angular/core'; | ||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
import { DaffCustomerPaymentRequestTransform } from '../models/public_api'; | ||
|
||
/** | ||
* A multi-provider injection token for registering customer payment request transforms. | ||
*/ | ||
export const DAFF_CUSTOMER_PAYMENT_REQUEST_TRANSFORMS = new InjectionToken<DaffCustomerPaymentRequestTransform[]>( | ||
export const { | ||
/** | ||
* A multi-provider injection token for registering customer payment request transforms. | ||
*/ | ||
token: DAFF_CUSTOMER_PAYMENT_REQUEST_TRANSFORMS, | ||
|
||
/** | ||
* Provides a customer payment request transform registration. | ||
* | ||
* See {@link DaffCustomerPaymentRequestTransform}. | ||
*/ | ||
provider: daffPaymentProvideAvailableProcessors, | ||
} = createMultiInjectionToken<DaffCustomerPaymentRequestTransform>( | ||
'DAFF_CUSTOMER_PAYMENT_REQUEST_TRANSFORMS', | ||
{ | ||
factory: () => [], | ||
providedIn: 'any', | ||
}, | ||
{ providedIn: 'any' }, | ||
); | ||
|
||
/** | ||
* Provides a customer payment request transform registration. | ||
* | ||
* See {@link DaffCustomerPaymentRequestTransform}. | ||
*/ | ||
export const daffPaymentProvideAvailableProcessors = (...transforms: DaffCustomerPaymentRequestTransform[]): ValueProvider[] => | ||
transforms.map(transform => ({ | ||
provide: DAFF_CUSTOMER_PAYMENT_REQUEST_TRANSFORMS, | ||
useValue: transform, | ||
multi: true, | ||
})); |
16 changes: 9 additions & 7 deletions
16
libs/customer-payment/state/src/injection-tokens/error-matcher.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_CUSTOMER_PAYMENT_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_CUSTOMER_PAYMENT_ERROR_MATCHER, | ||
provider: daffProvideCustomerPaymentErrorMatcher, | ||
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>( | ||
'DAFF_CUSTOMER_PAYMENT_ERROR_MATCHER', | ||
{ factory: () => daffTransformErrorToStateError }, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 12 additions & 9 deletions
21
libs/customer-payment/state/src/injection-tokens/transform-collection.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 25 additions & 36 deletions
61
libs/customer-payment/state/src/reducers/token/extra.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,31 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
import { ActionReducer } from '@ngrx/store'; | ||
|
||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
import { DaffCustomerPaymentReducersState } from '../reducers.interface'; | ||
|
||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffCustomerPaymentProvideExtraReducers}. | ||
*/ | ||
export const DAFF_CUSTOMER_PAYMENT_EXTRA_REDUCERS = new InjectionToken<ActionReducer<DaffCustomerPaymentReducersState>[]>( | ||
export const { | ||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffCustomerPaymentProvideExtraReducers}. | ||
*/ | ||
token: DAFF_CUSTOMER_PAYMENT_EXTRA_REDUCERS, | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil customer reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffCustomerPaymentProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffCustomerPaymentProvideExtraReducers, | ||
} = createMultiInjectionToken<ActionReducer<DaffCustomerPaymentReducersState>>( | ||
'DAFF_CUSTOMER_PAYMENT_EXTRA_REDUCERS', | ||
{ | ||
factory: () => [], | ||
providedIn: 'any', | ||
}, | ||
{ providedIn: 'any' }, | ||
); | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil customer reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffCustomerPaymentProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffCustomerPaymentProvideExtraReducers( | ||
...reducers: ActionReducer<DaffCustomerPaymentReducersState>[] | ||
): Provider[] { | ||
return reducers.map(reducer => ({ | ||
provide: DAFF_CUSTOMER_PAYMENT_EXTRA_REDUCERS, | ||
useValue: reducer, | ||
multi: true, | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters