-
-
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): create injection tokens with factory (#3241)
- Loading branch information
Showing
6 changed files
with
66 additions
and
66 deletions.
There are no files selected for viewing
17 changes: 11 additions & 6 deletions
17
libs/customer/driver/src/interfaces/address-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
13 changes: 8 additions & 5 deletions
13
libs/customer/driver/src/interfaces/customer-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/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_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_ERROR_MATCHER, | ||
provider: daffProvideCustomerErrorMatcher, | ||
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>( | ||
'DAFF_CUSTOMER_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { DAFF_CUSTOMER_ERROR_MATCHER } from './error-matcher.token'; | ||
export * from './error-matcher.token'; |
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 { DaffCustomerReducersState } from '../reducers.interface'; | ||
|
||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffCustomerProvideExtraReducers}. | ||
*/ | ||
export const DAFF_CUSTOMER_EXTRA_REDUCERS = new InjectionToken<ActionReducer<DaffCustomerReducersState>[]>( | ||
export const { | ||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffCustomerProvideExtraReducers}. | ||
*/ | ||
token: DAFF_CUSTOMER_EXTRA_REDUCERS, | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil customer reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffCustomerProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffCustomerProvideExtraReducers, | ||
} = createMultiInjectionToken<ActionReducer<DaffCustomerReducersState>>( | ||
'DAFF_CUSTOMER_EXTRA_REDUCERS', | ||
{ | ||
factory: () => [], | ||
providedIn: 'any', | ||
}, | ||
{ providedIn: 'any' }, | ||
); | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil customer reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffCustomerProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffCustomerProvideExtraReducers( | ||
...reducers: ActionReducer<DaffCustomerReducersState>[] | ||
): Provider[] { | ||
return reducers.map(reducer => ({ | ||
provide: DAFF_CUSTOMER_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