Commit 9c5d24c2 authored by Ryan Diehl's avatar Ryan Diehl

feat(properties): implement forRoot with initializer

parent a5fd1a0e
Pipeline #107574 passed with stages
in 4 minutes and 43 seconds
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { APP_INITIALIZER, InjectionToken, ModuleWithProviders, NgModule } from '@angular/core';
import { LoadingEventsModule } from '@psu/utils/loading-events';
import { LoggerModule } from '@psu/utils/logger';
import { PropertiesService } from './properties.service';
const PROPERTIES_CONFIG_TOKEN = new InjectionToken<string>('psu.utils.properties.config');
export function initializerFactory<T>(service: PropertiesService<T>, configUrl: string): () => Promise<any> {
// NOTE: assign promise to a variable to avoid compiler complaining about lambdas in static functions.
const promise = () => service.load(configUrl);
return promise;
}
@NgModule({
imports: [CommonModule, LoggerModule, LoadingEventsModule],
providers: [PropertiesService]
})
export class PropertiesModule {}
export class PropertiesModule {
static forRoot(configFile: string): ModuleWithProviders<PropertiesModule> {
return {
ngModule: PropertiesModule,
providers: [
PropertiesService,
{ provide: PROPERTIES_CONFIG_TOKEN, useValue: configFile },
{
provide: APP_INITIALIZER,
useFactory: initializerFactory,
multi: true,
deps: [PropertiesService, PROPERTIES_CONFIG_TOKEN],
},
],
};
}
}
  • SonarQube analysis indicates that quality gate is failed.

    • Bugs is failed: Actual value 1 > 0
    • high_severity_vulns is passed: Actual value 0
    • medium_severity_vulns is passed: Actual value 0

    SonarQube analysis reported 13 issues

    • 1 major
    • 🔽 7 minor
    • 5 info

    Top 10 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Unexpected empty source 📘
    2. 🔽 Add an "alt" attribute to this image. 📘
    3. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    4. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    5. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    6. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    7. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    8. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    9. Make sure that cookie is written safely here. 📘
    10. Make sure that using a regular expression is safe here. 📘
    • ... 3 more
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment