Skip to content

Commit

Permalink
perf(*): remove unnecessary optional attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Jul 1, 2024
1 parent 42a4250 commit b15c7f2
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 86 deletions.
6 changes: 3 additions & 3 deletions packages/abc/avatar-list/avatar-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/abc/error-collect/error-collect.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/abc/exception/exception.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/abc/global-footer/global-footer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/abc/loading/loading.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoadingDefaultComponent> | null = null;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/abc/onboarding/onboarding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnboardingComponent>;
private op$!: Subscription;
Expand Down Expand Up @@ -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))),
Expand Down
22 changes: 10 additions & 12 deletions packages/abc/page-header/page-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,7 +140,7 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit {

const obsList: Array<Observable<NzSafeAny>> = [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(),
Expand All @@ -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!]
});
}
Expand All @@ -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;
}
Expand All @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/abc/result/result.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand All @@ -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();
});
Expand Down
12 changes: 6 additions & 6 deletions packages/abc/reuse-tab/reuse-tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
});
Expand All @@ -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$),
Expand Down
9 changes: 1 addition & 8 deletions packages/abc/st/st-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' };
Expand Down Expand Up @@ -81,13 +81,6 @@ export class STExport {
}

async export(opt: STExportOptions): Promise<XlsxExportResult> {
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,
Expand Down
4 changes: 2 additions & 2 deletions packages/abc/st/st.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -254,7 +254,7 @@ export class STComponent implements AfterViewInit, OnChanges {
}
});

this.i18nSrv?.change
this.i18nSrv.change
.pipe(
takeUntilDestroyed(),
filter(() => this._columns.length > 0)
Expand Down
6 changes: 3 additions & 3 deletions packages/abc/tag-select/tag-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -48,8 +48,8 @@ export class TagSelectComponent implements OnInit {
@Output() readonly change = new EventEmitter<boolean>();

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();
});
Expand Down
26 changes: 10 additions & 16 deletions packages/form/src/sf.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, TemplateRef<void>>();
Expand Down Expand Up @@ -317,22 +317,16 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy {
this.cdr.markForCheck();
}
});
const refSchemas: Array<Observable<NzSafeAny> | 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<Observable<NzSafeAny>>))
.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 {
Expand Down
6 changes: 3 additions & 3 deletions packages/theme/layout-default/layout-nav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/theme/setting-drawer/setting-drawer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
Expand Down
Loading

0 comments on commit b15c7f2

Please sign in to comment.