Skip to content

Commit

Permalink
feat(all): use provider functions (#3288)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Oct 16, 2024
1 parent e9fc8dc commit 166a876
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 152 deletions.
7 changes: 2 additions & 5 deletions apps/daffio/src/app/app.server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -15,10 +15,7 @@ import { provideServerDocsPath } from './docs/services/docs-path-server';
providers: [
provideServerRendering(),
provideServerDocsPath(),
{
provide: DaffioAssetFetchService,
useExisting: DaffioAssetFetchServerService,
},
provideDaffioAssetFetchService(DaffioAssetFetchServerService),
],
})
export class AppServerModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

import {
provideDaffAuthorizeNetDriver,
DaffAuthorizeNetPaymentId,
provideDaffAuthorizeNetPaymentId,
} from '@daffodil/authorizenet/driver';
import { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory';

Expand All @@ -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,
),
Expand Down
7 changes: 2 additions & 5 deletions libs/authorizenet/driver/magento/src/authorize-net.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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),
],
};
}
Expand Down
8 changes: 2 additions & 6 deletions libs/cart-store-credit/driver/magento/src/driver.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
),
Expand Down
12 changes: 3 additions & 9 deletions libs/cart/driver/magento/src/injection-tokens/public_api.ts
Original file line number Diff line number Diff line change
@@ -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';
5 changes: 1 addition & 4 deletions libs/cart/driver/src/injection-tokens/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export {
daffCartDriverProvideFreePaymentMethod,
DAFF_CART_DRIVER_FREE_PAYMENT_METHOD,
} from './free-payment-method';
export * from './free-payment-method';
10 changes: 3 additions & 7 deletions libs/cart/guides/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -112,11 +112,7 @@ const extraCartFragment = gql`
@NgModule({
...,
providers: [
{
provide: DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS,
useValue: extraCartFragment,
multi: true
}
provideDaffCartMagentoExtraCartFragments(extraCartFragment)
]
})
class AppModule {}
Expand Down
13 changes: 5 additions & 8 deletions libs/cart/guides/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,18 @@ class AppModule {}

```ts
import {
DaffCartPaymentMethodIdMap,
provideDaffCartPaymentMethodIdMap,
DaffCartFacade,
DaffCartPaymentMethod
} from '@daffodil/cart';

@NgModule({
...,
providers: [
{
provide: DaffCartPaymentMethodIdMap,
useValue: {
authorizenet_accept_js: 'authorizenet',
payflowpro: 'paypal'
}
}
provideDaffCartPaymentMethodIdMap({
authorizenet_accept_js: 'authorizenet',
payflowpro: 'paypal'
})
]
})
class AppModule {}
Expand Down
4 changes: 2 additions & 2 deletions libs/cart/state/src/cart-state.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -48,7 +48,7 @@ import { DAFF_CART_REDUCERS } from './reducers/token/reducers.token';
]),
],
providers: [
{ provide: DaffCartItemStateDebounceTime, useValue: 4000 },
provideDaffCartItemStateDebounceTime(4000),
...daffPaymentProvideExtraReducers(combineReducers({
payment: daffCartPaymentReducer,
})),
Expand Down
2 changes: 1 addition & 1 deletion libs/cart/state/src/injection-tokens/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { DaffCartItemStateDebounceTime } from './cart-item-state-debounce-time';
export * from './cart-item-state-debounce-time';
export * from './error-matcher.token';
2 changes: 1 addition & 1 deletion libs/core/guides/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/storage/persistence-server-safe.token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const {
* Provides noop for the persistence service on the server.
*/
token: DaffServerSafePersistenceServiceToken,
provider: provideDaffDaffServerSafePersistenceServiceToken,
provider: provideDaffServerSafePersistenceServiceToken,
} = createSingleInjectionToken<DaffPersistenceService>(
'DaffServerSafePersistenceService',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>('thumbnailCompatToken');
7 changes: 2 additions & 5 deletions libs/driver/magento/src/magento.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
4 changes: 2 additions & 2 deletions libs/driver/src/http-client-cache/service.token.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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';

export const {
token: DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE,
provider: provideDaffDriverHttpClientCacheService,
} = createSingleInjectionToken<DaffDriverHttpClientCacheServiceInterface>(
} = createSingletonInjectionToken<DaffDriverHttpClientCacheServiceInterface>(
'DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE',
{ factory: () => inject(DaffDriverHttpClientCacheNoopService) },
);
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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),
],
};
}
Expand Down
8 changes: 2 additions & 6 deletions libs/related-products/state/src/state.module.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {}
8 changes: 2 additions & 6 deletions libs/search-category/driver/in-memory/src/in-memory.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -21,11 +21,7 @@ export class DaffSearchCategoryInMemoryDriverModule {
return {
ngModule: DaffSearchCategoryInMemoryDriverModule,
providers: [
{
provide: DAFF_SEARCH_IN_MEMORY_BACKENDS,
useExisting: DaffSearchCategoryInMemoryBackendService,
multi: true,
},
provideDaffSearchInMemoryBackends(DaffSearchCategoryInMemoryBackendService),
],
};
}
Expand Down
11 changes: 5 additions & 6 deletions libs/search-category/driver/magento/src/driver.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,11 +29,7 @@ export class DaffSearchCategoryMagentoDriverModule {
return {
ngModule: DaffSearchCategoryMagentoDriverModule,
providers: [
{
provide: DAFF_SEARCH_FEDERATED_DRIVERS,
multi: true,
useExisting: DaffSearchCategoryMagentoDriver,
},
provideDaffSearchFederatedDrivers(DaffSearchCategoryMagentoDriver),
],
};
}
Expand Down
8 changes: 2 additions & 6 deletions libs/search-product/driver/in-memory/src/in-memory.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -21,11 +21,7 @@ export class DaffSearchProductInMemoryDriverModule {
return {
ngModule: DaffSearchProductInMemoryDriverModule,
providers: [
{
provide: DAFF_SEARCH_IN_MEMORY_BACKENDS,
useExisting: DaffSearchProductInMemoryBackendService,
multi: true,
},
provideDaffSearchInMemoryBackends(DaffSearchProductInMemoryBackendService),
],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,11 +29,7 @@ export class DaffSearchProductMagentoFederatedDriverModule {
return {
ngModule: DaffSearchProductMagentoFederatedDriverModule,
providers: [
{
provide: DAFF_SEARCH_FEDERATED_DRIVERS,
multi: true,
useExisting: DaffSearchProductMagentoDriver,
},
provideDaffSearchFederatedDrivers(DaffSearchProductMagentoDriver),
],
};
}
Expand Down
Loading

0 comments on commit 166a876

Please sign in to comment.