Skip to content

Commit

Permalink
fix: remove all injector from constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
rfrt committed Sep 9, 2024
1 parent 3662856 commit 5213c93
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 61 deletions.
11 changes: 5 additions & 6 deletions projects/core/src/services/dialog.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@angular/core';
import { inject, Type } from '@angular/core';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
import { Observable, ReplaySubject, switchMap, take, throttleTime } from 'rxjs';

Expand All @@ -9,11 +9,10 @@ export abstract class NgxDialogService<ReturnType, DataType> {
protected dialogResponse$: Observable<ReturnType | undefined>;
protected dialogRef!: MatDialogRef<unknown, ReturnType>;

public constructor(
private lazyLoaderService: NgxLazyLoaderService,
private dialog: MatDialog,
matDialogConfig?: MatDialogConfig<DataType>
) {
protected lazyLoaderService = inject(NgxLazyLoaderService);
protected dialog = inject(MatDialog);

public constructor(matDialogConfig?: MatDialogConfig<DataType>) {
this.dialogResponse$ = this.openDialogSub$.pipe(
throttleTime(11),
take(1),
Expand Down
6 changes: 2 additions & 4 deletions projects/core/src/services/lazy-loader.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentType } from '@angular/cdk/portal';
import { Injectable, Injector, ɵcreateInjector as createInjector, Type } from '@angular/core';
import { ɵcreateInjector as createInjector, inject, Injectable, Injector, Type } from '@angular/core';
import { from, map, Observable } from 'rxjs';

export interface LoadModuleInfos<T> {
Expand All @@ -17,9 +17,7 @@ export abstract class NgxAbstractLazyModule<Component> {
providedIn: 'root'
})
export class NgxLazyLoaderService {
public constructor(
private injector: Injector
) {}
private injector = inject(Injector);

public loadModule$<T extends NgxAbstractLazyModule<unknown>>(path: Promise<Type<T>>, parentInjector?: Injector): Observable<LoadModuleInfos<T>> {
return from(path).pipe(
Expand Down
17 changes: 9 additions & 8 deletions projects/core/src/services/media.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, InjectionToken, NgZone, OnDestroy, Optional } from '@angular/core';
import { inject, Injectable, InjectionToken, NgZone, OnDestroy } from '@angular/core';
import { BehaviorSubject, distinctUntilChanged, map, Observable, shareReplay } from 'rxjs';

export interface NgxMediaQueryDefinition {
Expand Down Expand Up @@ -97,15 +97,16 @@ export class NgxMediaService implements OnDestroy {
public mediaChanged$ = new BehaviorSubject('lg');
public mql = {} as Record<string, MediaQueryList>;

public constructor(
private zone: NgZone,
@Optional() @Inject(mediaQueryDefinitions) mediaDefinitions?: NgxMediaQueryDefinition[]
) {
if (!mediaDefinitions) {
mediaDefinitions = simplifiedMediaQueryDefinitions;
private zone = inject(NgZone);
private mediaDefinitions? = inject<Array<NgxMediaQueryDefinition>>(mediaQueryDefinitions, { optional: true });


public constructor() {
if (!this.mediaDefinitions) {
this.mediaDefinitions = simplifiedMediaQueryDefinitions;
}

mediaDefinitions.forEach(mediaDefinition => {
this.mediaDefinitions.forEach(mediaDefinition => {
const { alias, mediaQuery } = mediaDefinition;
this.mql[alias] = window.matchMedia(mediaQuery);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Inject, inject, Injectable, InjectionToken, Optional, Type } from '@angular/core';
import { inject, Injectable, InjectionToken, Type } from '@angular/core';
import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core';
import { format, isValid, Locale, setHours, setMinutes, setSeconds } from 'date-fns';

import { validateAndParseDateStr } from './date.util';
import { DateTimeAdapter } from './date-time-adapter';
import { validateAndParseDateStr } from './date.util';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const ACCEPTED_NON_DATE_VALUES = new InjectionToken<readonly (string | RegExp)[]>('ACCEPTED_NON_DATE_VALUES');
Expand Down Expand Up @@ -37,13 +37,12 @@ export class NgxMultiFormatDateAdapter extends DateAdapter<TypeForAdapter, Local
private delegateType = inject<Type<DateAdapter<Date>>>(MULTI_FORMAT_DATE_DELEGATE);
// private matDateLocale = inject<Record<string, unknown>>(MAT_DATE_LOCALE, { optional: true }); //todo
private acceptedValues = inject<readonly (string | RegExp)[]>(ACCEPTED_NON_DATE_VALUES, { optional: true });
private matDateLocale = inject<Record<string, unknown>>(MAT_DATE_LOCALE);

public constructor(
@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: Record<string, unknown>
) {
public constructor() {
super();
this.locale = matDateLocale;
this.delegate = new this.delegateType(matDateLocale);
this.locale = this.matDateLocale;
this.delegate = new this.delegateType(this.matDateLocale);
}

public getYear(date: TypeForAdapter): number {
Expand Down
12 changes: 5 additions & 7 deletions projects/message-box-dialog/src/message-box-dialog.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Type } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { NgxAbstractLazyModule, NgxDialogService, NgxLazyLoaderService } from '@hug/ngx-core';
import { MatDialogConfig } from '@angular/material/dialog';
import { NgxAbstractLazyModule, NgxDialogService } from '@hug/ngx-core';
import { Observable, take } from 'rxjs';

import { NgxMessageBoxDialogButtons, NgxMessageBoxDialogData, NgxMessageBoxDialogResponse } from './message-box-dialog.model';
Expand All @@ -9,11 +9,9 @@ import { NgxMessageBoxDialogButtons, NgxMessageBoxDialogData, NgxMessageBoxDialo
providedIn: 'root'
})
export class NgxMessageBoxDialogService extends NgxDialogService<NgxMessageBoxDialogResponse, NgxMessageBoxDialogData | string> {
public constructor(
lazyLoaderService: NgxLazyLoaderService,
dialog: MatDialog
) {
super(lazyLoaderService, dialog, {

public constructor() {
super({
panelClass: 'no-padding-dialog'
} as MatDialogConfig<NgxMessageBoxDialogData>);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { Injectable, Type } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { NgxAbstractLazyModule, NgxDialogService, NgxLazyLoaderService } from '@hug/ngx-core';
import { MatDialogConfig } from '@angular/material/dialog';
import { NgxAbstractLazyModule, NgxDialogService } from '@hug/ngx-core';

import { NgxStatus } from '../status.model';

@Injectable({
providedIn: 'root'
})
export class NgxStatusDetailDialogService extends NgxDialogService<void, NgxStatus> {
public constructor(
lazyLoaderService: NgxLazyLoaderService,
dialog: MatDialog
) {
super(lazyLoaderService, dialog, {
public constructor() {
super({
disableClose: false,
hasBackdrop: true,
width: '700px',
Expand Down
15 changes: 7 additions & 8 deletions projects/status/src/status-detail/status-detail.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, Inject, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ChangeDetectionStrategy, Component, inject, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { NgxMessageBoxType } from '@hug/ngx-message-box';

import { NgxStatus } from '../status.model';
Expand All @@ -15,13 +15,12 @@ export class NgxStatusDetailComponent {
protected fullTextError: string;
protected messageBoxType: NgxMessageBoxType;

public constructor(
protected dialogRef: MatDialogRef<NgxStatusDetailComponent, void>,
@Inject(MAT_DIALOG_DATA) protected status: NgxStatus
) {
this.fullTextError = `Error Date: ${(status.date ?? new Date()).toUTCString()}\n${status.technicalText || ''}`;
protected status = inject<NgxStatus>(MAT_DIALOG_DATA);

switch (status.type) {
public constructor() {
this.fullTextError = `Error Date: ${(this.status.date ?? new Date()).toUTCString()}\n${this.status.technicalText || ''}`;

switch (this.status.type) {
case 'primary':
this.messageBoxType = 'primary';
break;
Expand Down
13 changes: 6 additions & 7 deletions projects/tooltip/src/tooltip.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ConnectedPosition } from '@angular/cdk/overlay';
import { Type } from '@angular/core';
import { inject, Type } from '@angular/core';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
import { NgxAbstractLazyModule, NgxLazyLoaderService, subscribeWith } from '@hug/ngx-core';
import { merge } from 'lodash-es';
import { debounceTime, delay, EMPTY, filter, fromEvent, map, mergeWith, Observable, shareReplay, Subject, switchMap, tap, withLatestFrom } from 'rxjs';

import { NgxTooltipConfig } from './tooltip.model';
import { NgxTooltipComponentInterface } from './tooltip-component.interface';
import { NgxTooltipConfig } from './tooltip.model';

export abstract class NgxTooltipService<D> {
protected close$ = new Subject<void>();
Expand Down Expand Up @@ -76,11 +76,10 @@ export abstract class NgxTooltipService<D> {
}
];

public constructor(
private lazyLoaderService: NgxLazyLoaderService,
private dialog: MatDialog,
private tooltipConfig?: MatDialogConfig<D>
) {
protected lazyLoaderService = inject(NgxLazyLoaderService);
protected dialog = inject(MatDialog);

public constructor(private tooltipConfig?: MatDialogConfig<D>) {
if (!this.tooltipConfig) {
this.tooltipConfig = new MatDialogConfig();
}
Expand Down
11 changes: 4 additions & 7 deletions projects/user-tooltip/src/user-tooltip.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { Injectable, Type } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { NgxAbstractLazyModule, NgxLazyLoaderService } from '@hug/ngx-core';
import { MatDialogConfig } from '@angular/material/dialog';
import { NgxAbstractLazyModule } from '@hug/ngx-core';
import { NgxTooltipComponentInterface, NgxTooltipService } from '@hug/ngx-tooltip';
import { NgxUserCard } from '@hug/ngx-user-card';

@Injectable({
providedIn: 'root'
})
export class NgxUserTooltipService extends NgxTooltipService<NgxUserCard> {
public constructor(
lazyLoaderService: NgxLazyLoaderService,
dialog: MatDialog
) {
super(lazyLoaderService, dialog, {
public constructor() {
super({
width: 'auto',
minWidth: '16px',
panelClass: 'no-padding-dialog'
Expand Down

0 comments on commit 5213c93

Please sign in to comment.