Skip to content

Commit

Permalink
feat: simplify provideFastSVG by removing classes that are provided i…
Browse files Browse the repository at this point in the history
…n root by default
  • Loading branch information
eneajaho committed Sep 13, 2023
1 parent 7421906 commit 0f88208
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions packages/ngx-fast-lib/src/lib/fast-svg.provider.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { Provider, makeEnvironmentProviders } from '@angular/core';
import {
SvgLoadStrategy,
SvgLoadStrategyImpl,
SvgOptions,
SvgOptionsToken,
SvgRegistry,
} from '..';
import { Provider } from '@angular/core';
import { SvgLoadStrategy, SvgOptions, SvgOptionsToken } from '..';
import { FastSvgProviderOptions } from './provider-config.interface';

/**
* @description
* Use this function to register the FastSvg providers in your application.
*
* @param options {FastSvgProviderOptions} - The options for the FastSvg providers.
* @return { EnvironmentProviders } - The providers for the FastSvg module.
* @return { Provider[] } - The providers for the FastSvg module.
*
* @example
*
Expand All @@ -26,21 +20,23 @@ import { FastSvgProviderOptions } from './provider-config.interface';
* ]});
* ```
*/
export const provideFastSVG = (options: FastSvgProviderOptions) => {
const svgOptions: SvgOptions = {
url: options.url,
suspenseSvgString: options.suspenseSvgString || undefined,
defaultSize: options.defaultSize || undefined,
};

export const provideFastSVG = (options: FastSvgProviderOptions): Provider[] => {
const providers: Provider[] = [
SvgRegistry,
{
provide: SvgLoadStrategy,
useClass: options.svgLoadStrategy || SvgLoadStrategyImpl,
provide: SvgOptionsToken,
useValue: {
url: options.url,
suspenseSvgString: options.suspenseSvgString || undefined,
defaultSize: options.defaultSize || undefined,
} as SvgOptions,
},
{ provide: SvgOptionsToken, useValue: svgOptions },
];

if (options.svgLoadStrategy) {
providers.push(
{ provide: SvgLoadStrategy, useClass: options.svgLoadStrategy } as Provider
);
}

return providers;
};

0 comments on commit 0f88208

Please sign in to comment.