import { Inject , Injectable , Optional } from '@angular/core' ; import { deepMergeKey } from '@delon/util/other' ; import type { NzSafeAny } from 'ng-zorro-antd/core/types' ; import { AlainConfig , AlainConfigKey , ALAIN_CONFIG } from './config.types' ; @ Injectable ( { providedIn : 'root' } ) export class AlainConfigService { private config : AlainConfig ; constructor ( @ Optional ( ) @ Inject ( ALAIN_CONFIG ) defaultConfig ? ) { this . config = { ... defaultConfig } ; } get < T extends AlainConfigKey > ( componentName , key ? ) { const res = ( ( this . config [ componentName ] as { [ key ] : unknown ; } ) || { } ) as NzSafeAny ; return key ? { [ key ] : res [ key ] } : res ; } merge < T extends AlainConfigKey > ( componentName , ... defaultValues ) { return deepMergeKey ( { } , true , ... defaultValues , this . get ( componentName ) ) ; } attach < T extends AlainConfigKey > ( componentThis , componentName , defaultValues ) { Object . assign ( componentThis , this . merge ( componentName , defaultValues ) ) ; } attachKey < T extends AlainConfigKey > ( componentThis , componentName , key ) { Object . assign ( componentThis , this . get ( componentName , key ) ) ; } set < T extends AlainConfigKey > ( componentName , value ) { this . config [ componentName ] = { ... this . config [ componentName ] , ... value } ; } }