From c2c5da5ff188f99d7b011c028bdd7c54bf5694e3 Mon Sep 17 00:00:00 2001 From: Peter Lauck Date: Wed, 16 Oct 2024 18:48:00 +0000 Subject: [PATCH] feat(all): use provider functions --- apps/daffio/src/app/app.server.module.ts | 7 ++--- .../drivers/authorize-net-driver.module.ts | 7 ++--- .../magento/src/authorize-net.module.ts | 7 ++--- .../driver/magento/src/driver.module.ts | 8 ++--- .../src/injection-tokens/public_api.ts | 12 ++------ .../driver/src/injection-tokens/public_api.ts | 5 +--- libs/cart/guides/extensions.md | 10 ++----- libs/cart/guides/usage.md | 13 ++++----- libs/cart/state/src/cart-state.module.ts | 4 +-- .../state/src/injection-tokens/public_api.ts | 2 +- libs/core/guides/storage.md | 2 +- .../storage/persistence-server-safe.token.ts | 2 +- .../src/thumbnail/thumbnail-compat.token.ts | 2 +- libs/driver/magento/src/magento.module.ts | 7 ++--- .../src/http-client-cache/service.token.ts | 4 +-- .../driver/in-memory/src/in-memory.module.ts | 8 ++--- .../state/src/state.module.ts | 8 ++--- .../driver/in-memory/src/in-memory.module.ts | 8 ++--- .../driver/magento/src/driver.module.ts | 11 ++++--- .../driver/in-memory/src/in-memory.module.ts | 8 ++--- .../magento/src/federated-driver.module.ts | 11 ++++--- .../seo/router/src/canonical/updates.token.ts | 29 ++++++++++--------- libs/seo/router/src/meta/updates.token.ts | 27 +++++++++-------- libs/seo/router/src/title/updates.token.ts | 28 +++++++++--------- .../driver/in-memory/src/in-memory.module.ts | 8 ++--- .../upsell-products/state/src/state.module.ts | 8 ++--- 26 files changed, 94 insertions(+), 152 deletions(-) diff --git a/apps/daffio/src/app/app.server.module.ts b/apps/daffio/src/app/app.server.module.ts index dc2ea4e4db..74ec967c02 100644 --- a/apps/daffio/src/app/app.server.module.ts +++ b/apps/daffio/src/app/app.server.module.ts @@ -4,7 +4,7 @@ import { provideServerRendering } from '@angular/platform-server'; import { DaffioAppComponent } from './app.component'; import { AppModule } from './app.module'; import { DaffioAssetFetchServerService } from './core/assets/fetch/server.service'; -import { DaffioAssetFetchService } from './core/assets/fetch/service.interface'; +import { provideDaffioAssetFetchService } from './core/assets/fetch/service.interface'; import { provideServerDocsPath } from './docs/services/docs-path-server'; @NgModule({ @@ -15,10 +15,7 @@ import { provideServerDocsPath } from './docs/services/docs-path-server'; providers: [ provideServerRendering(), provideServerDocsPath(), - { - provide: DaffioAssetFetchService, - useExisting: DaffioAssetFetchServerService, - }, + provideDaffioAssetFetchService(DaffioAssetFetchServerService), ], }) export class AppServerModule {} diff --git a/libs/authorizenet/driver/in-memory/src/drivers/authorize-net-driver.module.ts b/libs/authorizenet/driver/in-memory/src/drivers/authorize-net-driver.module.ts index 259568f543..b04fd2ff72 100644 --- a/libs/authorizenet/driver/in-memory/src/drivers/authorize-net-driver.module.ts +++ b/libs/authorizenet/driver/in-memory/src/drivers/authorize-net-driver.module.ts @@ -6,7 +6,7 @@ import { import { provideDaffAuthorizeNetDriver, - DaffAuthorizeNetPaymentId, + provideDaffAuthorizeNetPaymentId, } from '@daffodil/authorizenet/driver'; import { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory'; @@ -26,10 +26,7 @@ export class DaffAuthorizeNetInMemoryDriverModule { ngModule: DaffAuthorizeNetInMemoryDriverModule, providers: [ provideDaffAuthorizeNetDriver(DaffInMemoryAuthorizeNetService), - { - provide: DaffAuthorizeNetPaymentId, - useValue: DAFF_IN_MEMORY_AUTHORIZE_NET_PAYMENT_ID, - }, + provideDaffAuthorizeNetPaymentId(DAFF_IN_MEMORY_AUTHORIZE_NET_PAYMENT_ID), provideDaffInMemoryBackends( DaffInMemoryBackendAuthorizenetService, ), diff --git a/libs/authorizenet/driver/magento/src/authorize-net.module.ts b/libs/authorizenet/driver/magento/src/authorize-net.module.ts index e023b63fce..c148a1d57c 100644 --- a/libs/authorizenet/driver/magento/src/authorize-net.module.ts +++ b/libs/authorizenet/driver/magento/src/authorize-net.module.ts @@ -9,7 +9,7 @@ import { provideDaffAuthorizeNetConfigToken, provideDaffAuthorizeNetDriver, provideDaffAuthorizeNetPaymentDriver, - DaffAuthorizeNetPaymentId, + provideDaffAuthorizeNetPaymentId, } from '@daffodil/authorizenet/driver'; import { MAGENTO_AUTHORIZE_NET_PAYMENT_ID } from './authorize-net-payment-id'; @@ -33,10 +33,7 @@ export class DaffMagentoAuthorizeNetDriverModule { provideDaffAuthorizeNetConfigToken(config), provideDaffAuthorizeNetDriver(DaffMagentoAuthorizeNetService), provideDaffAuthorizeNetPaymentDriver(DaffMagentoAuthorizeNetPaymentService), - { - provide: DaffAuthorizeNetPaymentId, - useValue: MAGENTO_AUTHORIZE_NET_PAYMENT_ID, - }, + provideDaffAuthorizeNetPaymentId(MAGENTO_AUTHORIZE_NET_PAYMENT_ID), ], }; } diff --git a/libs/cart-store-credit/driver/magento/src/driver.module.ts b/libs/cart-store-credit/driver/magento/src/driver.module.ts index 11edf1abd7..152bb6303c 100644 --- a/libs/cart-store-credit/driver/magento/src/driver.module.ts +++ b/libs/cart-store-credit/driver/magento/src/driver.module.ts @@ -6,7 +6,7 @@ import { import { provideDaffCartMagentoCartTransforms, - DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS, + provideDaffCartMagentoExtraCartFragments, } from '@daffodil/cart/driver/magento'; import { provideDaffCartStoreCreditDriver } from '@daffodil/cart-store-credit/driver'; @@ -25,11 +25,7 @@ export class DaffCartStoreCreditMagentoDriverModule { ngModule: DaffCartStoreCreditMagentoDriverModule, providers: [ provideDaffCartStoreCreditDriver(DaffCartStoreCreditMagentoService), - { - provide: DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS, - useValue: magentoCartStoreCreditFragment, - multi: true, - }, + provideDaffCartMagentoExtraCartFragments(magentoCartStoreCreditFragment), provideDaffCartMagentoCartTransforms( magentoCartWithStoreCreditTransform, ), diff --git a/libs/cart/driver/magento/src/injection-tokens/public_api.ts b/libs/cart/driver/magento/src/injection-tokens/public_api.ts index 14b8128bd4..72d12095fd 100644 --- a/libs/cart/driver/magento/src/injection-tokens/public_api.ts +++ b/libs/cart/driver/magento/src/injection-tokens/public_api.ts @@ -1,9 +1,3 @@ -export { DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS } from './fragments/cart'; -export { - provideDaffCartMagentoCartItemTransforms, - DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS, -} from './transforms/cart-item/token'; -export { - provideDaffCartMagentoCartTransforms, - DAFF_CART_MAGENTO_CART_TRANSFORMS, -} from './transforms/cart/token'; +export * from './fragments/cart'; +export * from './transforms/cart-item/token'; +export * from './transforms/cart/token'; diff --git a/libs/cart/driver/src/injection-tokens/public_api.ts b/libs/cart/driver/src/injection-tokens/public_api.ts index 1357f8468e..56af4fef04 100644 --- a/libs/cart/driver/src/injection-tokens/public_api.ts +++ b/libs/cart/driver/src/injection-tokens/public_api.ts @@ -1,4 +1 @@ -export { - daffCartDriverProvideFreePaymentMethod, - DAFF_CART_DRIVER_FREE_PAYMENT_METHOD, -} from './free-payment-method'; +export * from './free-payment-method'; diff --git a/libs/cart/guides/extensions.md b/libs/cart/guides/extensions.md index db1b785625..9226e0a567 100644 --- a/libs/cart/guides/extensions.md +++ b/libs/cart/guides/extensions.md @@ -81,7 +81,7 @@ Only drivers that use GraphQL support extensible fragments because fragments are - Magento ### Magento -Provide the `DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS` to query additional fields on a Magento cart query. This applies to all of the driver calls that return a `DaffCart`, which is most of them. +Use `provideDaffCartMagentoExtraCartFragments` to query additional fields on a Magento cart query. This applies to all of the driver calls that return a `DaffCart`, which is most of them. The additional fields are present on the untyped `extra_attributes` field. @@ -90,7 +90,7 @@ The following example demonstrates providing a GraphQL document using the `graph ```ts import gql from 'graphql-tag'; import { - DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS, + provideDaffCartMagentoExtraCartFragments, DaffCartFacade, DaffCartLoad, DaffCart @@ -112,11 +112,7 @@ const extraCartFragment = gql` @NgModule({ ..., providers: [ - { - provide: DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS, - useValue: extraCartFragment, - multi: true - } + provideDaffCartMagentoExtraCartFragments(extraCartFragment) ] }) class AppModule {} diff --git a/libs/cart/guides/usage.md b/libs/cart/guides/usage.md index a82f405bd1..69f95f5591 100644 --- a/libs/cart/guides/usage.md +++ b/libs/cart/guides/usage.md @@ -48,7 +48,7 @@ class AppModule {} ```ts import { - DaffCartPaymentMethodIdMap, + provideDaffCartPaymentMethodIdMap, DaffCartFacade, DaffCartPaymentMethod } from '@daffodil/cart'; @@ -56,13 +56,10 @@ import { @NgModule({ ..., providers: [ - { - provide: DaffCartPaymentMethodIdMap, - useValue: { - authorizenet_accept_js: 'authorizenet', - payflowpro: 'paypal' - } - } + provideDaffCartPaymentMethodIdMap({ + authorizenet_accept_js: 'authorizenet', + payflowpro: 'paypal' + }) ] }) class AppModule {} diff --git a/libs/cart/state/src/cart-state.module.ts b/libs/cart/state/src/cart-state.module.ts index d1c264d823..4585216746 100644 --- a/libs/cart/state/src/cart-state.module.ts +++ b/libs/cart/state/src/cart-state.module.ts @@ -22,7 +22,7 @@ import { DaffCartShippingAddressEffects } from './effects/cart-shipping-address. import { DaffCartShippingInformationEffects } from './effects/cart-shipping-information.effects'; import { DaffCartShippingMethodsEffects } from './effects/cart-shipping-methods.effects'; import { DaffCartEffects } from './effects/cart.effects'; -import { DaffCartItemStateDebounceTime } from './injection-tokens/cart-item-state-debounce-time'; +import { provideDaffCartItemStateDebounceTime } from './injection-tokens/cart-item-state-debounce-time'; import { daffCartPaymentReducer } from './reducers/cart-payment/payment.reducer'; import { DAFF_CART_STORE_FEATURE_KEY } from './reducers/public_api'; import { DAFF_CART_STORE_CONFIG } from './reducers/token/config.token'; @@ -48,7 +48,7 @@ import { DAFF_CART_REDUCERS } from './reducers/token/reducers.token'; ]), ], providers: [ - { provide: DaffCartItemStateDebounceTime, useValue: 4000 }, + provideDaffCartItemStateDebounceTime(4000), ...daffPaymentProvideExtraReducers(combineReducers({ payment: daffCartPaymentReducer, })), diff --git a/libs/cart/state/src/injection-tokens/public_api.ts b/libs/cart/state/src/injection-tokens/public_api.ts index d60f706056..23fef0b25a 100644 --- a/libs/cart/state/src/injection-tokens/public_api.ts +++ b/libs/cart/state/src/injection-tokens/public_api.ts @@ -1,2 +1,2 @@ -export { DaffCartItemStateDebounceTime } from './cart-item-state-debounce-time'; +export * from './cart-item-state-debounce-time'; export * from './error-matcher.token'; diff --git a/libs/core/guides/storage.md b/libs/core/guides/storage.md index ace49d7ea0..4877336833 100644 --- a/libs/core/guides/storage.md +++ b/libs/core/guides/storage.md @@ -29,7 +29,7 @@ import { { provide: DaffPersistenceServiceToken, deps: [PLATFORM_ID], - factory: (platformId: string) => isPlatformBrowser(platformId) + useFactory: (platformId: string) => isPlatformBrowser(platformId) ? new DaffLocalStorageService(platformId) : new DaffErrorStorageService() } diff --git a/libs/core/src/storage/persistence-server-safe.token.ts b/libs/core/src/storage/persistence-server-safe.token.ts index 5558a01018..4046791d4e 100644 --- a/libs/core/src/storage/persistence-server-safe.token.ts +++ b/libs/core/src/storage/persistence-server-safe.token.ts @@ -16,7 +16,7 @@ export const { * Provides noop for the persistence service on the server. */ token: DaffServerSafePersistenceServiceToken, - provider: provideDaffDaffServerSafePersistenceServiceToken, + provider: provideDaffServerSafePersistenceServiceToken, } = createSingleInjectionToken( 'DaffServerSafePersistenceService', { diff --git a/libs/design/media-gallery/src/thumbnail/thumbnail-compat.token.ts b/libs/design/media-gallery/src/thumbnail/thumbnail-compat.token.ts index ce553240cd..e26e1037b6 100644 --- a/libs/design/media-gallery/src/thumbnail/thumbnail-compat.token.ts +++ b/libs/design/media-gallery/src/thumbnail/thumbnail-compat.token.ts @@ -5,5 +5,5 @@ export const { * A multi provider injection token that marks a component as renderable for the `DaffMediaRendererComponent`. */ token: daffThumbnailCompatToken, - provider: provideDaffdaffThumbnailCompatToken, + provider: provideDaffThumbnailCompatToken, } = createSingleInjectionToken('thumbnailCompatToken'); diff --git a/libs/driver/magento/src/magento.module.ts b/libs/driver/magento/src/magento.module.ts index 15ec292fe2..a1d65b6196 100644 --- a/libs/driver/magento/src/magento.module.ts +++ b/libs/driver/magento/src/magento.module.ts @@ -1,15 +1,12 @@ import { NgModule } from '@angular/core'; -import { DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE } from '@daffodil/driver'; +import { provideDaffDriverHttpClientCacheService } from '@daffodil/driver'; import { DaffDriverHttpClientCacheMagentoService } from './graphql/cache.service'; @NgModule({ providers: [ - { - provide: DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE, - useExisting: DaffDriverHttpClientCacheMagentoService, - }, + provideDaffDriverHttpClientCacheService(DaffDriverHttpClientCacheMagentoService), ], }) export class DaffDriverMagentoModule {} diff --git a/libs/driver/src/http-client-cache/service.token.ts b/libs/driver/src/http-client-cache/service.token.ts index 1f7fd4207c..a3d2a6a608 100644 --- a/libs/driver/src/http-client-cache/service.token.ts +++ b/libs/driver/src/http-client-cache/service.token.ts @@ -1,6 +1,6 @@ import { inject } from '@angular/core'; -import { createSingleInjectionToken } from '@daffodil/core'; +import { createSingletonInjectionToken } from '@daffodil/core'; import { DaffDriverHttpClientCacheNoopService } from './noop.service'; import { DaffDriverHttpClientCacheServiceInterface } from './service.type'; @@ -8,7 +8,7 @@ import { DaffDriverHttpClientCacheServiceInterface } from './service.type'; export const { token: DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE, provider: provideDaffDriverHttpClientCacheService, -} = createSingleInjectionToken( +} = createSingletonInjectionToken( 'DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE', { factory: () => inject(DaffDriverHttpClientCacheNoopService) }, ); diff --git a/libs/related-products/driver/in-memory/src/in-memory.module.ts b/libs/related-products/driver/in-memory/src/in-memory.module.ts index 497fc1d3bd..5deea7fed8 100644 --- a/libs/related-products/driver/in-memory/src/in-memory.module.ts +++ b/libs/related-products/driver/in-memory/src/in-memory.module.ts @@ -4,7 +4,7 @@ import { ModuleWithProviders, } from '@angular/core'; -import { DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS } from '@daffodil/product/driver/in-memory'; +import { provideDaffProductInMemoryExtraProductResponseTransforms } from '@daffodil/product/driver/in-memory'; import { provideDaffProductExtraProductFactories } from '@daffodil/product/testing'; import { DaffRelatedProductFactory } from '@daffodil/related-products/testing'; @@ -24,11 +24,7 @@ export class DaffRelatedProductsInMemoryDriverModule { ngModule: DaffRelatedProductsInMemoryDriverModule, providers: [ provideDaffProductExtraProductFactories(DaffRelatedProductFactory), - { - provide: DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS, - useValue: transformInMemoryRelatedProducts, - multi: true, - }, + provideDaffProductInMemoryExtraProductResponseTransforms(transformInMemoryRelatedProducts), ], }; } diff --git a/libs/related-products/state/src/state.module.ts b/libs/related-products/state/src/state.module.ts index bec5469993..89ee5b9977 100644 --- a/libs/related-products/state/src/state.module.ts +++ b/libs/related-products/state/src/state.module.ts @@ -1,7 +1,7 @@ import { NgModule } from '@angular/core'; import { StoreModule } from '@ngrx/store'; -import { DAFF_PRODUCT_META_REDUCERS } from '@daffodil/product/state'; +import { daffProductProvideMetaReducers } from '@daffodil/product/state'; import { DAFF_RELATED_PRODUCTS_STORE_FEATURE_KEY, @@ -17,11 +17,7 @@ import { StoreModule.forFeature(DAFF_RELATED_PRODUCTS_STORE_FEATURE_KEY, daffRelatedProductsReducers), ], providers: [ - { - provide: DAFF_PRODUCT_META_REDUCERS, - multi: true, - useValue: daffRelatedProductsDedupeMetaReducer, - }, + daffProductProvideMetaReducers(daffRelatedProductsDedupeMetaReducer), ], }) export class DaffRelatedProductStateModule {} diff --git a/libs/search-category/driver/in-memory/src/in-memory.module.ts b/libs/search-category/driver/in-memory/src/in-memory.module.ts index 5bdcb1d150..a5a7453eaf 100644 --- a/libs/search-category/driver/in-memory/src/in-memory.module.ts +++ b/libs/search-category/driver/in-memory/src/in-memory.module.ts @@ -4,7 +4,7 @@ import { ModuleWithProviders, } from '@angular/core'; -import { DAFF_SEARCH_IN_MEMORY_BACKENDS } from '@daffodil/search/driver/in-memory'; +import { provideDaffSearchInMemoryBackends } from '@daffodil/search/driver/in-memory'; import { DaffSearchCategoryInMemoryBackendService } from './backend/search.service'; @@ -21,11 +21,7 @@ export class DaffSearchCategoryInMemoryDriverModule { return { ngModule: DaffSearchCategoryInMemoryDriverModule, providers: [ - { - provide: DAFF_SEARCH_IN_MEMORY_BACKENDS, - useExisting: DaffSearchCategoryInMemoryBackendService, - multi: true, - }, + provideDaffSearchInMemoryBackends(DaffSearchCategoryInMemoryBackendService), ], }; } diff --git a/libs/search-category/driver/magento/src/driver.module.ts b/libs/search-category/driver/magento/src/driver.module.ts index 9c55876d9b..92ca72abff 100644 --- a/libs/search-category/driver/magento/src/driver.module.ts +++ b/libs/search-category/driver/magento/src/driver.module.ts @@ -5,7 +5,10 @@ import { } from '@angular/core'; import { provideDaffMagentoCacheableOperation } from '@daffodil/driver/magento'; -import { DAFF_SEARCH_FEDERATED_DRIVERS } from '@daffodil/search/driver/federated'; +import { + DAFF_SEARCH_FEDERATED_DRIVERS, + provideDaffSearchFederatedDrivers, +} from '@daffodil/search/driver/federated'; import { DaffSearchCategoryMagentoDriver } from './category-search.service'; import { DAFF_MAGENTO_SEARCH_FOR_CATEGORIES_QUERY_NAME } from './queries/category-search'; @@ -26,11 +29,7 @@ export class DaffSearchCategoryMagentoDriverModule { return { ngModule: DaffSearchCategoryMagentoDriverModule, providers: [ - { - provide: DAFF_SEARCH_FEDERATED_DRIVERS, - multi: true, - useExisting: DaffSearchCategoryMagentoDriver, - }, + provideDaffSearchFederatedDrivers(DaffSearchCategoryMagentoDriver), ], }; } diff --git a/libs/search-product/driver/in-memory/src/in-memory.module.ts b/libs/search-product/driver/in-memory/src/in-memory.module.ts index dccf245226..47e995d6b2 100644 --- a/libs/search-product/driver/in-memory/src/in-memory.module.ts +++ b/libs/search-product/driver/in-memory/src/in-memory.module.ts @@ -4,7 +4,7 @@ import { ModuleWithProviders, } from '@angular/core'; -import { DAFF_SEARCH_IN_MEMORY_BACKENDS } from '@daffodil/search/driver/in-memory'; +import { provideDaffSearchInMemoryBackends } from '@daffodil/search/driver/in-memory'; import { DaffSearchProductInMemoryBackendService } from './backend/search.service'; @@ -21,11 +21,7 @@ export class DaffSearchProductInMemoryDriverModule { return { ngModule: DaffSearchProductInMemoryDriverModule, providers: [ - { - provide: DAFF_SEARCH_IN_MEMORY_BACKENDS, - useExisting: DaffSearchProductInMemoryBackendService, - multi: true, - }, + provideDaffSearchInMemoryBackends(DaffSearchProductInMemoryBackendService), ], }; } diff --git a/libs/search-product/driver/magento/src/federated-driver.module.ts b/libs/search-product/driver/magento/src/federated-driver.module.ts index 4bd052c3c7..d24778038b 100644 --- a/libs/search-product/driver/magento/src/federated-driver.module.ts +++ b/libs/search-product/driver/magento/src/federated-driver.module.ts @@ -4,7 +4,10 @@ import { ModuleWithProviders, } from '@angular/core'; -import { DAFF_SEARCH_FEDERATED_DRIVERS } from '@daffodil/search/driver/federated'; +import { + DAFF_SEARCH_FEDERATED_DRIVERS, + provideDaffSearchFederatedDrivers, +} from '@daffodil/search/driver/federated'; import { DaffSearchProductMagentoCoreModule } from './core.module'; import { DaffSearchProductMagentoDriver } from './product-search.service'; @@ -26,11 +29,7 @@ export class DaffSearchProductMagentoFederatedDriverModule { return { ngModule: DaffSearchProductMagentoFederatedDriverModule, providers: [ - { - provide: DAFF_SEARCH_FEDERATED_DRIVERS, - multi: true, - useExisting: DaffSearchProductMagentoDriver, - }, + provideDaffSearchFederatedDrivers(DaffSearchProductMagentoDriver), ], }; } diff --git a/libs/seo/router/src/canonical/updates.token.ts b/libs/seo/router/src/canonical/updates.token.ts index 6f5bb86030..51b707e6a2 100644 --- a/libs/seo/router/src/canonical/updates.token.ts +++ b/libs/seo/router/src/canonical/updates.token.ts @@ -1,16 +1,19 @@ -import { - Provider, - InjectionToken, -} from '@angular/core'; +import { Provider } from '@angular/core'; import { Event } from '@angular/router'; +import { createMultiInjectionToken } from '@daffodil/core'; + import { DaffSeoUpdateEventPair } from '../model/update-event-pair.interface'; -/** - * A multi-provider injection token for providing canonical URL update logic. - * `getData` will run in response to, and invoked with, the action specified. - */ -export const DAFF_SEO_CANONICAL_URL_ROUTER_UPDATES = new InjectionToken[]>('DAFF_SEO_CANONICAL_URL_ROUTER_UPDATES', { factory: () => []}); + +const { + /** + * A multi-provider injection token for providing canonical URL update logic. + * `getData` will run in response to, and invoked with, the action specified. + */ + token: DAFF_SEO_CANONICAL_URL_ROUTER_UPDATES, + provider, +} = createMultiInjectionToken>('DAFF_SEO_CANONICAL_URL_ROUTER_UPDATES'); /** * Provides canonical URL update logic. @@ -26,9 +29,7 @@ export const DAFF_SEO_CANONICAL_URL_ROUTER_UPDATES = new InjectionToken(...values: DaffSeoUpdateEventPair[]): Provider[] { - return values.map(value => ({ - provide: DAFF_SEO_CANONICAL_URL_ROUTER_UPDATES, - useValue: value, - multi: true, - })); + return provider(...values); } + +export { DAFF_SEO_CANONICAL_URL_ROUTER_UPDATES }; diff --git a/libs/seo/router/src/meta/updates.token.ts b/libs/seo/router/src/meta/updates.token.ts index ff7ec64ba3..4fda5e0af4 100644 --- a/libs/seo/router/src/meta/updates.token.ts +++ b/libs/seo/router/src/meta/updates.token.ts @@ -1,18 +1,19 @@ -import { - InjectionToken, - Provider, -} from '@angular/core'; +import { Provider } from '@angular/core'; import { Event } from '@angular/router'; +import { createMultiInjectionToken } from '@daffodil/core'; import { DaffSeoMetaDefinition } from '@daffodil/seo'; import { DaffSeoUpdateEventPair } from '../model/update-event-pair.interface'; -/** - * A multi-provider injection token for providing page meta update logic. - * `getData` will run in response to, and invoked with, the action specified. - */ -export const DAFF_SEO_META_ROUTER_UPDATES = new InjectionToken[]>('DAFF_SEO_META_ROUTER_UPDATES', { factory: () => []}); +const { + /** + * A multi-provider injection token for providing page meta update logic. + * `getData` will run in response to, and invoked with, the action specified. + */ + token: DAFF_SEO_META_ROUTER_UPDATES, + provider, +} = createMultiInjectionToken>('DAFF_SEO_META_ROUTER_UPDATES'); /** * Provides page meta update logic. @@ -28,9 +29,7 @@ export const DAFF_SEO_META_ROUTER_UPDATES = new InjectionToken(...values: DaffSeoUpdateEventPair[]): Provider[] { - return values.map(value => ({ - provide: DAFF_SEO_META_ROUTER_UPDATES, - useValue: value, - multi: true, - })); + return provider(...values); } + +export { DAFF_SEO_META_ROUTER_UPDATES }; diff --git a/libs/seo/router/src/title/updates.token.ts b/libs/seo/router/src/title/updates.token.ts index 7ec4ddaa31..e873928289 100644 --- a/libs/seo/router/src/title/updates.token.ts +++ b/libs/seo/router/src/title/updates.token.ts @@ -1,16 +1,18 @@ -import { - Provider, - InjectionToken, -} from '@angular/core'; +import { Provider } from '@angular/core'; import { Event } from '@angular/router'; +import { createMultiInjectionToken } from '@daffodil/core'; + import { DaffSeoUpdateEventPair } from '../model/update-event-pair.interface'; -/** - * A multi-provider injection token for providing canonical URL update logic. - * `getData` will run in response to, and invoked with, the action specified. - */ -export const DAFF_SEO_TITLE_ROUTER_UPDATES = new InjectionToken[]>('DAFF_SEO_TITLE_ROUTER_UPDATES', { factory: () => []}); +const { + /** + * A multi-provider injection token for providing canonical URL update logic. + * `getData` will run in response to, and invoked with, the action specified. + */ + token: DAFF_SEO_TITLE_ROUTER_UPDATES, + provider, +} = createMultiInjectionToken>('DAFF_SEO_TITLE_ROUTER_UPDATES'); /** * Provides canonical URL update logic. @@ -26,9 +28,7 @@ export const DAFF_SEO_TITLE_ROUTER_UPDATES = new InjectionToken(...values: DaffSeoUpdateEventPair[]): Provider[] { - return values.map(value => ({ - provide: DAFF_SEO_TITLE_ROUTER_UPDATES, - useValue: value, - multi: true, - })); + return provider(...values); } + +export { DAFF_SEO_TITLE_ROUTER_UPDATES }; diff --git a/libs/upsell-products/driver/in-memory/src/in-memory.module.ts b/libs/upsell-products/driver/in-memory/src/in-memory.module.ts index 5a928ec905..4b7f608dfc 100644 --- a/libs/upsell-products/driver/in-memory/src/in-memory.module.ts +++ b/libs/upsell-products/driver/in-memory/src/in-memory.module.ts @@ -4,7 +4,7 @@ import { ModuleWithProviders, } from '@angular/core'; -import { DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS } from '@daffodil/product/driver/in-memory'; +import { provideDaffProductInMemoryExtraProductResponseTransforms } from '@daffodil/product/driver/in-memory'; import { provideDaffProductExtraProductFactories } from '@daffodil/product/testing'; import { DaffUpsellProductFactory } from '@daffodil/upsell-products/testing'; @@ -24,11 +24,7 @@ export class DaffUpsellProductsInMemoryDriverModule { ngModule: DaffUpsellProductsInMemoryDriverModule, providers: [ provideDaffProductExtraProductFactories(DaffUpsellProductFactory), - { - provide: DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS, - useValue: transformInMemoryUpsellProducts, - multi: true, - }, + provideDaffProductInMemoryExtraProductResponseTransforms(transformInMemoryUpsellProducts), ], }; } diff --git a/libs/upsell-products/state/src/state.module.ts b/libs/upsell-products/state/src/state.module.ts index 0de76f242d..a77f47642e 100644 --- a/libs/upsell-products/state/src/state.module.ts +++ b/libs/upsell-products/state/src/state.module.ts @@ -1,7 +1,7 @@ import { NgModule } from '@angular/core'; import { StoreModule } from '@ngrx/store'; -import { DAFF_PRODUCT_META_REDUCERS } from '@daffodil/product/state'; +import { daffProductProvideMetaReducers } from '@daffodil/product/state'; import { DAFF_UPSELL_PRODUCTS_STORE_FEATURE_KEY, @@ -17,11 +17,7 @@ import { StoreModule.forFeature(DAFF_UPSELL_PRODUCTS_STORE_FEATURE_KEY, daffUpsellProductsReducers), ], providers: [ - { - provide: DAFF_PRODUCT_META_REDUCERS, - multi: true, - useValue: daffUpsellProductsDedupeMetaReducer, - }, + daffProductProvideMetaReducers(daffUpsellProductsDedupeMetaReducer), ], }) export class DaffUpsellProductStateModule {}