-
-
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(product-composite): create injection tokens with factory (#3256)
- Loading branch information
Showing
6 changed files
with
56 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
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
57 changes: 23 additions & 34 deletions
57
libs/product-composite/state/src/reducers/injection-tokens/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,39 +1,28 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
import { ActionReducer } from '@ngrx/store'; | ||
|
||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
import { DaffCompositeProductReducersState } from '../composite-product-reducers-state.interface'; | ||
|
||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffProductCompositeProvideExtraReducers}. | ||
*/ | ||
export const DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS = new InjectionToken<ActionReducer<DaffCompositeProductReducersState>[]>( | ||
'DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS', | ||
{ factory: () => []}, | ||
); | ||
export const { | ||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffProductCompositeProvideExtraReducers}. | ||
*/ | ||
token: DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS, | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil cart reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProductCompositeProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffProductCompositeProvideExtraReducers( | ||
...reducers: ActionReducer<Partial<DaffCompositeProductReducersState>>[] | ||
): Provider[] { | ||
return reducers.map(reducer => ({ | ||
provide: DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS, | ||
useValue: reducer, | ||
multi: true, | ||
})); | ||
} | ||
/** | ||
* Provides additional reducers that run after the standard Daffodil cart reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProductCompositeProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffProductCompositeProvideExtraReducers, | ||
} = createMultiInjectionToken<ActionReducer<DaffCompositeProductReducersState>>('DAFF_PRODUCT_COMPOSITE_EXTRA_REDUCERS'); |
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