Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(driver): create injection tokens with factory #3247

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { InjectionToken } from '@angular/core';
import { createMultiInjectionToken } from '@daffodil/core';

/**
* A multi-provider injection token of the operation names of magento queries that should
* be cached. This is needed because queries need to be converted into GET queries in order for Magento
* to cache them. This token should be used by daffodil driver platform modules to register operation names that are cacheable, and is
* intended for internal daffodil use only.
*/
export const DAFF_MAGENTO_CACHEABLE_OPERATIONS = new InjectionToken<string[]>('DAFF_MAGENTO_CACHEABLE_OPERATIONS', { factory: () => []});
export const {
/**
* A multi-provider injection token of the operation names of magento queries that should
* be cached. This is needed because queries need to be converted into GET queries in order for Magento
* to cache them. This token should be used by daffodil driver platform modules to register operation names that are cacheable, and is
* intended for internal daffodil use only.
*/
token: DAFF_MAGENTO_CACHEABLE_OPERATIONS,
/**
* Adds many operation names to the list of cacheable Magento operations. Use only with Angular 9+.
*/
provider: provideManyDaffMagentoCacheableOperations,
} = createMultiInjectionToken<string>('DAFF_MAGENTO_CACHEABLE_OPERATIONS');

/**
* Adds an operation name to the list of cacheable Magento operations. Use only with Angular 9+.
Expand All @@ -18,14 +24,3 @@ export function provideDaffMagentoCacheableOperation(operationName: string) {
multi: true,
};
}

/**
* Adds many operation names to the list of cacheable Magento operations. Use only with Angular 9+.
*/
export function provideManyDaffMagentoCacheableOperations(...operationNames: string[]) {
return operationNames.map(name => ({
provide: DAFF_MAGENTO_CACHEABLE_OPERATIONS,
useValue: name,
multi: true,
}));
}
15 changes: 10 additions & 5 deletions libs/driver/src/http-client-cache/service.token.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {
InjectionToken,
inject,
} from '@angular/core';
import { inject } from '@angular/core';

import { createSingleInjectionToken } from '@daffodil/core';

import { DaffDriverHttpClientCacheNoopService } from './noop.service';
import { DaffDriverHttpClientCacheServiceInterface } from './service.type';

export const DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE = new InjectionToken<DaffDriverHttpClientCacheServiceInterface>('DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE', { factory: () => inject(DaffDriverHttpClientCacheNoopService) });
export const {
token: DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE,
provider: daffProvideDriverHttpClientCacheService,
} = createSingleInjectionToken<DaffDriverHttpClientCacheServiceInterface>(
'DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE',
{ factory: () => inject(DaffDriverHttpClientCacheNoopService) },
);
Loading