-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(customer-store-credit): create injection tokens with factory (#3245
- Loading branch information
Showing
5 changed files
with
55 additions
and
60 deletions.
There are no files selected for viewing
13 changes: 8 additions & 5 deletions
13
libs/customer-store-credit/driver/src/interfaces/store-credit-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
16 changes: 9 additions & 7 deletions
16
libs/customer-store-credit/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_STORE_CREDIT_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_STORE_CREDIT_ERROR_MATCHER, | ||
provider: daffProvideCustomerStoreCreditErrorMatcher, | ||
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>( | ||
'DAFF_CUSTOMER_STORE_CREDIT_ERROR_MATCHER', | ||
{ factory: () => daffTransformErrorToStateError }, | ||
); |
2 changes: 1 addition & 1 deletion
2
libs/customer-store-credit/state/src/injection-tokens/public_api.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 +1 @@ | ||
export { DAFF_CUSTOMER_STORE_CREDIT_ERROR_MATCHER } from './error-matcher.token'; | ||
export * from './error-matcher.token'; |
61 changes: 25 additions & 36 deletions
61
libs/customer-store-credit/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 { DaffCustomerStoreCreditReducersState } from '../reducers.interface'; | ||
|
||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffCustomerStoreCreditProvideExtraReducers}. | ||
*/ | ||
export const DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS = new InjectionToken<ActionReducer<DaffCustomerStoreCreditReducersState>[]>( | ||
export const { | ||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffCustomerStoreCreditProvideExtraReducers}. | ||
*/ | ||
token: DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS, | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil customer reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffCustomerStoreCreditProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffCustomerStoreCreditProvideExtraReducers, | ||
} = createMultiInjectionToken<ActionReducer<DaffCustomerStoreCreditReducersState>>( | ||
'DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS', | ||
{ | ||
factory: () => [], | ||
providedIn: 'any', | ||
}, | ||
{ providedIn: 'any' }, | ||
); | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil customer reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffCustomerStoreCreditProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffCustomerStoreCreditProvideExtraReducers( | ||
...reducers: ActionReducer<DaffCustomerStoreCreditReducersState>[] | ||
): Provider[] { | ||
return reducers.map(reducer => ({ | ||
provide: DAFF_CUSTOMER_STORE_CREDIT_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