From b15c7f22eeec39e6601d3d427d14d67ea759c6f6 Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 1 Jul 2024 15:09:16 +0800 Subject: [PATCH 1/2] perf(*): remove unnecessary optional attributes --- .../abc/avatar-list/avatar-list.component.ts | 6 ++--- .../error-collect/error-collect.component.ts | 6 ++--- packages/abc/exception/exception.component.ts | 6 ++--- .../global-footer/global-footer.component.ts | 6 ++--- packages/abc/loading/loading.service.ts | 4 +-- packages/abc/onboarding/onboarding.service.ts | 4 +-- .../abc/page-header/page-header.component.ts | 22 +++++++--------- packages/abc/result/result.component.ts | 6 ++--- packages/abc/reuse-tab/reuse-tab.component.ts | 12 ++++----- packages/abc/st/st-export.ts | 9 +------ packages/abc/st/st.component.ts | 4 +-- .../abc/tag-select/tag-select.component.ts | 6 ++--- packages/form/src/sf.component.ts | 26 +++++++------------ .../layout-default/layout-nav.component.ts | 6 ++--- .../setting-drawer.component.ts | 6 ++--- .../theme/src/services/menu/menu.service.ts | 12 ++++----- .../theme/src/services/title/title.service.ts | 10 +++---- .../theme/theme-btn/theme-btn.component.ts | 6 ++--- 18 files changed, 71 insertions(+), 86 deletions(-) diff --git a/packages/abc/avatar-list/avatar-list.component.ts b/packages/abc/avatar-list/avatar-list.component.ts index 1afbee9f5..9619074be 100644 --- a/packages/abc/avatar-list/avatar-list.component.ts +++ b/packages/abc/avatar-list/avatar-list.component.ts @@ -38,7 +38,7 @@ import { AvatarListItemComponent } from './avatar-list-item.component'; }) export class AvatarListComponent implements AfterViewInit, OnChanges { private readonly cdr = inject(ChangeDetectorRef); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly destroy$ = inject(DestroyRef); private inited = false; @@ -79,8 +79,8 @@ export class AvatarListComponent implements AfterViewInit, OnChanges { } ngAfterViewInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/abc/error-collect/error-collect.component.ts b/packages/abc/error-collect/error-collect.component.ts index b6cbaac45..74acc763d 100644 --- a/packages/abc/error-collect/error-collect.component.ts +++ b/packages/abc/error-collect/error-collect.component.ts @@ -42,7 +42,7 @@ export class ErrorCollectComponent implements OnInit { private readonly el: HTMLElement = inject(ElementRef).nativeElement; private readonly cdr = inject(ChangeDetectorRef); private readonly doc = inject(DOCUMENT); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly platform = inject(Platform); private readonly destroy$ = inject(DestroyRef); @@ -83,8 +83,8 @@ export class ErrorCollectComponent implements OnInit { } private install(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/abc/exception/exception.component.ts b/packages/abc/exception/exception.component.ts index d2b6cce21..917a2f2e3 100644 --- a/packages/abc/exception/exception.component.ts +++ b/packages/abc/exception/exception.component.ts @@ -43,7 +43,7 @@ export class ExceptionComponent implements OnInit { private readonly i18n = inject(DelonLocaleService); private readonly dom = inject(DomSanitizer); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly cdr = inject(ChangeDetectorRef); private readonly destroy$ = inject(DestroyRef); @@ -116,8 +116,8 @@ export class ExceptionComponent implements OnInit { } ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/abc/global-footer/global-footer.component.ts b/packages/abc/global-footer/global-footer.component.ts index 926f4c7cc..9a33e8457 100644 --- a/packages/abc/global-footer/global-footer.component.ts +++ b/packages/abc/global-footer/global-footer.component.ts @@ -39,7 +39,7 @@ export class GlobalFooterComponent implements OnInit { private readonly router = inject(Router); private readonly win = inject(WINDOW); private readonly dom = inject(DomSanitizer); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly cdr = inject(ChangeDetectorRef); private readonly destroy$ = inject(DestroyRef); @@ -74,8 +74,8 @@ export class GlobalFooterComponent implements OnInit { } ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/abc/loading/loading.service.ts b/packages/abc/loading/loading.service.ts index fecb84609..cdaacd78c 100644 --- a/packages/abc/loading/loading.service.ts +++ b/packages/abc/loading/loading.service.ts @@ -13,7 +13,7 @@ import { LoadingShowOptions } from './loading.types'; export class LoadingService implements OnDestroy { private readonly overlay = inject(Overlay); private readonly configSrv = inject(AlainConfigService); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private _overlayRef?: OverlayRef; private compRef: ComponentRef | null = null; @@ -55,7 +55,7 @@ export class LoadingService implements OnDestroy { backdropClass: 'loading-backdrop' }); this.compRef = this._overlayRef.attach(new ComponentPortal(LoadingDefaultComponent)); - const dir = this.configSrv.get('loading')!.direction || this.directionality?.value; + const dir = this.configSrv.get('loading')!.direction || this.directionality.value; if (this.instance != null) { this.instance!!.options = this.opt; this.instance!!.dir = dir; diff --git a/packages/abc/onboarding/onboarding.service.ts b/packages/abc/onboarding/onboarding.service.ts index 83193cb7a..af2a282f2 100644 --- a/packages/abc/onboarding/onboarding.service.ts +++ b/packages/abc/onboarding/onboarding.service.ts @@ -28,7 +28,7 @@ export class OnboardingService implements OnDestroy { private readonly doc = inject(DOCUMENT); private readonly configSrv = inject(AlainConfigService); private readonly keyStoreSrv = inject(ONBOARDING_STORE_TOKEN); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private compRef!: ComponentRef; private op$!: Subscription; @@ -116,7 +116,7 @@ export class OnboardingService implements OnDestroy { ...this.i18n.getData('onboarding'), ...items[this.active] } as OnboardingItem; - const dir = this.configSrv.get('onboarding')!.direction || this.directionality?.value; + const dir = this.configSrv.get('onboarding')!.direction || this.directionality.value; Object.assign(this.compRef.instance, { item, config: this.config, active: this.active, max: items.length, dir }); const pipes = [ switchMap(() => (item.url ? this.router.navigateByUrl(item.url) : of(true))), diff --git a/packages/abc/page-header/page-header.component.ts b/packages/abc/page-header/page-header.component.ts index 6d357f140..f42bdb47c 100644 --- a/packages/abc/page-header/page-header.component.ts +++ b/packages/abc/page-header/page-header.component.ts @@ -63,10 +63,10 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit { private readonly router = inject(Router); private readonly cdr = inject(ChangeDetectorRef); private readonly menuSrv = inject(MenuService); - private readonly i18nSrv = inject(ALAIN_I18N_TOKEN, { optional: true }); - private readonly titleSrv = inject(TitleService, { optional: true }); + private readonly i18nSrv = inject(ALAIN_I18N_TOKEN); + private readonly titleSrv = inject(TitleService); private readonly reuseSrv = inject(ReuseTabService, { optional: true }); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly destroy$ = inject(DestroyRef); @ViewChild('conTpl', { static: false }) private conTpl!: ElementRef; @@ -140,7 +140,7 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit { const obsList: Array> = [this.router.events.pipe(filter(ev => ev instanceof NavigationEnd))]; if (this.menuSrv != null) obsList.push(this.menuSrv.change); - if (this.i18nSrv != null) obsList.push(this.i18nSrv.change); + obsList.push(this.i18nSrv.change); merge(...obsList) .pipe( takeUntilDestroyed(), @@ -163,13 +163,13 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit { this.menus.forEach(item => { if (typeof item.hideInBreadcrumb !== 'undefined' && item.hideInBreadcrumb) return; let title = item.text; - if (item.i18n && this.i18nSrv) title = this.i18nSrv.fanyi(item.i18n); + if (item.i18n) title = this.i18nSrv.fanyi(item.i18n); paths.push({ title, link: (item.link && [item.link]) as string[] }); }); // add home if (this.home) { paths.splice(0, 0, { - title: (this.homeI18n && this.i18nSrv && this.i18nSrv.fanyi(this.homeI18n)) || this.home, + title: (this.homeI18n && this.i18nSrv.fanyi(this.homeI18n)) || this.home, link: [this.homeLink!] }); } @@ -180,16 +180,14 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit { if (this._title == null && this._titleTpl == null && this.autoTitle && this.menus.length > 0) { const item = this.menus[this.menus.length - 1]; let title = item.text; - if (item.i18n && this.i18nSrv) { + if (item.i18n) { title = this.i18nSrv.fanyi(item.i18n); } this._titleVal = title!; } if (this._titleVal && this.syncTitle) { - if (this.titleSrv) { - this.titleSrv.setTitle(this._titleVal); - } + this.titleSrv.setTitle(this._titleVal); if (!this.inited && this.reuseSrv) { this.reuseSrv.title = this._titleVal; } @@ -207,8 +205,8 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit { } ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/abc/result/result.component.ts b/packages/abc/result/result.component.ts index c6b975f12..5a0e06700 100644 --- a/packages/abc/result/result.component.ts +++ b/packages/abc/result/result.component.ts @@ -31,7 +31,7 @@ import { NzIconDirective } from 'ng-zorro-antd/icon'; }) export class ResultComponent implements OnInit { private readonly cdr = inject(ChangeDetectorRef); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly destroy$ = inject(DestroyRef); _type = ''; @@ -58,8 +58,8 @@ export class ResultComponent implements OnInit { dir?: Direction = 'ltr'; ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/abc/reuse-tab/reuse-tab.component.ts b/packages/abc/reuse-tab/reuse-tab.component.ts index 7954f7a31..e381accb9 100644 --- a/packages/abc/reuse-tab/reuse-tab.component.ts +++ b/packages/abc/reuse-tab/reuse-tab.component.ts @@ -79,10 +79,10 @@ export class ReuseTabComponent implements OnInit, OnChanges { private readonly cdr = inject(ChangeDetectorRef); private readonly router = inject(Router); private readonly route = inject(ActivatedRoute); - private readonly i18nSrv = inject(ALAIN_I18N_TOKEN, { optional: true }); + private readonly i18nSrv = inject(ALAIN_I18N_TOKEN); private readonly doc = inject(DOCUMENT); private readonly platform = inject(Platform); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly stateKey = inject(REUSE_TAB_STORAGE_KEY); private readonly stateSrv = inject(REUSE_TAB_STORAGE_STATE); @@ -124,7 +124,7 @@ export class ReuseTabComponent implements OnInit, OnChanges { // #endregion private genTit(title: ReuseTitle): string { - return title.i18n && this.i18nSrv ? this.i18nSrv.fanyi(title.i18n) : title.text!; + return title.i18n ? this.i18nSrv.fanyi(title.i18n) : title.text!; } private get curUrl(): string { @@ -302,8 +302,8 @@ export class ReuseTabComponent implements OnInit, OnChanges { // #endregion ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); @@ -327,7 +327,7 @@ export class ReuseTabComponent implements OnInit, OnChanges { this.genList(res); }); - this.i18nSrv?.change + this.i18nSrv.change .pipe( filter(() => this.srv.inited), takeUntilDestroyed(this.destroy$), diff --git a/packages/abc/st/st-export.ts b/packages/abc/st/st-export.ts index b1daca433..bdd480e88 100644 --- a/packages/abc/st/st-export.ts +++ b/packages/abc/st/st-export.ts @@ -9,7 +9,7 @@ import { _STColumn } from './st.types'; @Injectable() export class STExport { - private readonly xlsxSrv = inject(XlsxService, { optional: true }); + private readonly xlsxSrv = inject(XlsxService); private _stGet(item: NzSafeAny, col: STColumn, index: number, colIndex: number): NzSafeAny { const ret: { [key: string]: NzSafeAny } = { t: 's', v: '' }; @@ -81,13 +81,6 @@ export class STExport { } async export(opt: STExportOptions): Promise { - if (this.xlsxSrv == null) { - if (typeof ngDevMode === 'undefined' || ngDevMode) { - console.warn(`XlsxService service not found`); - } - return Promise.reject(); - } - const sheets = this.genSheet(opt); return this.xlsxSrv.export({ sheets, diff --git a/packages/abc/st/st.component.ts b/packages/abc/st/st.component.ts index a9f8c922e..c7768cbf7 100644 --- a/packages/abc/st/st.component.ts +++ b/packages/abc/st/st.component.ts @@ -94,7 +94,7 @@ import type { _STColumn, _STDataValue, _STHeader, _STTdNotify, _STTdNotifyType } encapsulation: ViewEncapsulation.None }) export class STComponent implements AfterViewInit, OnChanges { - private readonly i18nSrv = inject(ALAIN_I18N_TOKEN, { optional: true }); + private readonly i18nSrv = inject(ALAIN_I18N_TOKEN); private readonly el: HTMLElement = inject(ElementRef).nativeElement; private readonly cdr = inject(ChangeDetectorRef); private readonly doc = inject(DOCUMENT); @@ -254,7 +254,7 @@ export class STComponent implements AfterViewInit, OnChanges { } }); - this.i18nSrv?.change + this.i18nSrv.change .pipe( takeUntilDestroyed(), filter(() => this._columns.length > 0) diff --git a/packages/abc/tag-select/tag-select.component.ts b/packages/abc/tag-select/tag-select.component.ts index e952c7184..460634024 100644 --- a/packages/abc/tag-select/tag-select.component.ts +++ b/packages/abc/tag-select/tag-select.component.ts @@ -36,7 +36,7 @@ import { NzIconDirective } from 'ng-zorro-antd/icon'; }) export class TagSelectComponent implements OnInit { private readonly i18n = inject(DelonLocaleService); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly cdr = inject(ChangeDetectorRef); private readonly destroy$ = inject(DestroyRef); locale: LocaleData = {}; @@ -48,8 +48,8 @@ export class TagSelectComponent implements OnInit { @Output() readonly change = new EventEmitter(); ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/form/src/sf.component.ts b/packages/form/src/sf.component.ts index 2283c3043..aadb4edf9 100644 --- a/packages/form/src/sf.component.ts +++ b/packages/form/src/sf.component.ts @@ -19,7 +19,7 @@ import { } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { DomSanitizer } from '@angular/platform-browser'; -import { merge, Observable, filter } from 'rxjs'; +import { merge, filter } from 'rxjs'; import { ACLService } from '@delon/acl'; import { ALAIN_I18N_TOKEN, DelonLocaleService, LocaleData } from '@delon/theme'; @@ -82,8 +82,8 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy { private readonly dom = inject(DomSanitizer); private readonly cdr = inject(ChangeDetectorRef); private readonly localeSrv = inject(DelonLocaleService); - private readonly aclSrv = inject(ACLService, { optional: true }); - private readonly i18nSrv = inject(ALAIN_I18N_TOKEN, { optional: true }); + private readonly aclSrv = inject(ACLService); + private readonly i18nSrv = inject(ALAIN_I18N_TOKEN); private readonly platform = inject(Platform); private _renders = new Map>(); @@ -317,22 +317,16 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy { this.cdr.markForCheck(); } }); - const refSchemas: Array | null> = [ - this.aclSrv ? this.aclSrv.change : null, - this.i18nSrv ? this.i18nSrv.change : null - ].filter(o => o != null); - if (refSchemas.length > 0) { - merge(...(refSchemas as Array>)) - .pipe( - filter(() => this._inited), - takeUntilDestroyed() - ) - .subscribe(() => this.refreshSchema()); - } + merge(this.aclSrv.change, this.i18nSrv.change) + .pipe( + filter(() => this._inited), + takeUntilDestroyed() + ) + .subscribe(() => this.refreshSchema()); } protected fanyi(key: string): string { - return (this.i18nSrv ? this.i18nSrv.fanyi(key) : '') || key; + return this.i18nSrv.fanyi(key) || key; } private inheritUI(ui: SFUISchemaItemRun): void { diff --git a/packages/theme/layout-default/layout-nav.component.ts b/packages/theme/layout-default/layout-nav.component.ts index b432f2882..6faada881 100644 --- a/packages/theme/layout-default/layout-nav.component.ts +++ b/packages/theme/layout-default/layout-nav.component.ts @@ -56,7 +56,7 @@ export class LayoutDefaultNavComponent implements OnInit, OnDestroy { private readonly cdr = inject(ChangeDetectorRef); private readonly ngZone = inject(NgZone); private readonly sanitizer = inject(DomSanitizer); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private bodyEl!: HTMLBodyElement; private destroy$ = inject(DestroyRef); @@ -259,8 +259,8 @@ export class LayoutDefaultNavComponent implements OnInit, OnDestroy { .subscribe(() => this.clearFloating()); this.underPad(); - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/theme/setting-drawer/setting-drawer.component.ts b/packages/theme/setting-drawer/setting-drawer.component.ts index 810f44390..0a7fccb0d 100644 --- a/packages/theme/setting-drawer/setting-drawer.component.ts +++ b/packages/theme/setting-drawer/setting-drawer.component.ts @@ -39,7 +39,7 @@ export class SettingDrawerComponent implements OnInit { private readonly lazy = inject(LazyService); private readonly ngZone = inject(NgZone); private readonly doc = inject(DOCUMENT); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly destroy$ = inject(DestroyRef); @Input({ transform: booleanAttribute }) autoApplyColor = true; @@ -72,8 +72,8 @@ export class SettingDrawerComponent implements OnInit { } ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); diff --git a/packages/theme/src/services/menu/menu.service.ts b/packages/theme/src/services/menu/menu.service.ts index 09594f374..425eebe19 100644 --- a/packages/theme/src/services/menu/menu.service.ts +++ b/packages/theme/src/services/menu/menu.service.ts @@ -12,8 +12,8 @@ import { Menu, MenuIcon, MenuInner } from './interface'; */ @Injectable({ providedIn: 'root' }) export class MenuService implements OnDestroy { - private readonly i18nSrv = inject(ALAIN_I18N_TOKEN, { optional: true }); - private readonly aclService = inject(ACLService, { optional: true }); + private readonly i18nSrv = inject(ALAIN_I18N_TOKEN); + private readonly aclService = inject(ACLService); private _change$: BehaviorSubject = new BehaviorSubject([]); private i18n$?: Subscription; private data: Menu[] = []; @@ -23,7 +23,7 @@ export class MenuService implements OnDestroy { openStrictly = false; constructor() { - this.i18n$ = this.i18nSrv?.change.subscribe(() => this.resume()); + this.i18n$ = this.i18nSrv.change.subscribe(() => this.resume()); } get change(): Observable { @@ -93,7 +93,7 @@ export class MenuService implements OnDestroy { item.icon = { theme: 'outline', spin: false, ...(item.icon as MenuIcon) }; } - item.text = item.i18n && this.i18nSrv ? this.i18nSrv.fanyi(item.i18n) : item.text; + item.text = item.i18n ? this.i18nSrv.fanyi(item.i18n) : item.text; // group item.group = item.group !== false; @@ -105,7 +105,7 @@ export class MenuService implements OnDestroy { item.disabled = typeof item.disabled === 'undefined' ? false : item.disabled; // acl - item._aclResult = item.acl && this.aclService ? this.aclService.can(item.acl) : true; + item._aclResult = item.acl ? this.aclService.can(item.acl) : true; item.open = item.open != null ? item.open : false; } @@ -162,7 +162,7 @@ export class MenuService implements OnDestroy { this.data[0].children!.splice(pos, 0, shortcutMenu); } let _data = this.data[0].children![pos]; - if (_data.i18n && this.i18nSrv) _data.text = this.i18nSrv.fanyi(_data.i18n); + if (_data.i18n) _data.text = this.i18nSrv.fanyi(_data.i18n); _data = Object.assign(_data, { shortcutRoot: true, _id: -1, diff --git a/packages/theme/src/services/title/title.service.ts b/packages/theme/src/services/title/title.service.ts index 8c55b5686..bf0a53008 100644 --- a/packages/theme/src/services/title/title.service.ts +++ b/packages/theme/src/services/title/title.service.ts @@ -28,10 +28,10 @@ export class TitleService implements OnDestroy { private readonly injector = inject(Injector); private readonly title = inject(Title); private readonly menuSrv = inject(MenuService); - private readonly i18nSrv = inject(ALAIN_I18N_TOKEN, { optional: true }); + private readonly i18nSrv = inject(ALAIN_I18N_TOKEN); constructor() { - this.i18nSrv?.change.pipe(takeUntilDestroyed()).subscribe(() => this.setTitle()); + this.i18nSrv.change.pipe(takeUntilDestroyed()).subscribe(() => this.setTitle()); } /** @@ -109,7 +109,7 @@ export class TitleService implements OnDestroy { let next = this.injector.get(ActivatedRoute); while (next.firstChild) next = next.firstChild; const data: RouteTitle = (next.snapshot && next.snapshot.data) || {}; - if (data.titleI18n && this.i18nSrv) data.title = this.i18nSrv.fanyi(data.titleI18n); + if (data.titleI18n) data.title = this.i18nSrv.fanyi(data.titleI18n); return isObservable(data.title) ? data.title : of(data.title!); } @@ -119,7 +119,7 @@ export class TitleService implements OnDestroy { const item = menus[menus.length - 1]; let title; - if (item.i18n && this.i18nSrv) title = this.i18nSrv.fanyi(item.i18n); + if (item.i18n) title = this.i18nSrv.fanyi(item.i18n); return of(title || item.text!); } @@ -157,7 +157,7 @@ export class TitleService implements OnDestroy { * Set i18n key of the document title */ setTitleByI18n(key: string, params?: unknown): void { - this.setTitle(this.i18nSrv?.fanyi(key, params)); + this.setTitle(this.i18nSrv.fanyi(key, params)); } ngOnDestroy(): void { diff --git a/packages/theme/theme-btn/theme-btn.component.ts b/packages/theme/theme-btn/theme-btn.component.ts index 4f9388b30..cce86a3e2 100644 --- a/packages/theme/theme-btn/theme-btn.component.ts +++ b/packages/theme/theme-btn/theme-btn.component.ts @@ -46,7 +46,7 @@ export class ThemeBtnComponent implements OnInit, OnDestroy { private readonly platform = inject(Platform); private readonly renderer = inject(Renderer2); private readonly configSrv = inject(AlainConfigService); - private readonly directionality = inject(Directionality, { optional: true }); + private readonly directionality = inject(Directionality); private readonly cdr = inject(ChangeDetectorRef); private readonly destroy$ = inject(DestroyRef); @@ -64,8 +64,8 @@ export class ThemeBtnComponent implements OnInit, OnDestroy { private key = inject(ALAIN_THEME_BTN_KEYS, { optional: true }) ?? 'site-theme'; ngOnInit(): void { - this.dir = this.directionality?.value; - this.directionality?.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe((direction: Direction) => { + this.dir = this.directionality.value; + this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe((direction: Direction) => { this.dir = direction; this.cdr.detectChanges(); }); From 7952279456b0353de18e961fe96c9de310f653a4 Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 1 Jul 2024 15:33:54 +0800 Subject: [PATCH 2/2] chore: fix test --- packages/abc/page-header/page-header.spec.ts | 4 ---- scripts/site/route-paths.txt | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/abc/page-header/page-header.spec.ts b/packages/abc/page-header/page-header.spec.ts index 720bf54ac..947e1bcd0 100644 --- a/packages/abc/page-header/page-header.spec.ts +++ b/packages/abc/page-header/page-header.spec.ts @@ -352,10 +352,6 @@ describe('abc: page-header', () => { beforeEach(() => { genModule({ providers: [ - { - provide: TitleService, - useFactory: () => null - }, { provide: ReuseTabService, useFactory: () => null diff --git a/scripts/site/route-paths.txt b/scripts/site/route-paths.txt index 1abc811d3..001a23c6b 100644 --- a/scripts/site/route-paths.txt +++ b/scripts/site/route-paths.txt @@ -21,6 +21,8 @@ /auth/set/zh /cache/getting-started/en /cache/getting-started/zh +/cache/interceptor/en +/cache/interceptor/zh /cache/service/en /cache/service/zh /chart/bar/en @@ -342,4 +344,4 @@ /util/pipes-format/en /util/pipes-format/zh /util/token/en -/util/token/zh +/util/token/zh \ No newline at end of file