Skip to content

Commit fa246bb

Browse files
committed
perf(frontend): replace toSignal with selectSignal
+ replace all toSignal(store.select) calls with store.selectSignal
1 parent 6d24ede commit fa246bb

File tree

9 files changed

+31
-36
lines changed

9 files changed

+31
-36
lines changed

frontend/src/app/app.component.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
MatSidenav,
1212
MatSidenavContent,
1313
} from '@angular/material/sidenav';
14-
import { map } from 'rxjs';
1514
import { TranslateModule, TranslateService } from '@ngx-translate/core';
1615
import { MatIconButton } from '@angular/material/button';
1716
import { MatIcon } from '@angular/material/icon';
@@ -22,7 +21,7 @@ import {
2221
MatListItemIcon,
2322
} from '@angular/material/list';
2423
import { Store } from '@ngrx/store';
25-
import { selectAuthTokenResponse } from './entities/auth/state/auth.selectors';
24+
import { selectAuthIsAuthorized } from './entities/auth/state/auth.selectors';
2625
import { AuthActions } from './entities/auth/state/auth.actions';
2726
import { selectAppIsOffline } from './state/app.selectors';
2827
import { MatProgressSpinner } from '@angular/material/progress-spinner';
@@ -62,9 +61,9 @@ export class AppComponent {
6261
private readonly store = inject(Store);
6362
private readonly translateService = inject(TranslateService);
6463

65-
public readonly isOffline = toSignal(this.store.select(selectAppIsOffline));
64+
public readonly isOffline = this.store.selectSignal(selectAppIsOffline);
6665

67-
private readonly isAdmin = toSignal(this.store.select(selectUserIsAdmin));
66+
private readonly isAdmin = this.store.selectSignal(selectUserIsAdmin);
6867
private readonly navTranslates = toSignal(this.translateService.get('NAV'));
6968
public readonly links = computed<INavItem[]>(() => {
7069
const isAdmin = this.isAdmin();
@@ -106,8 +105,8 @@ export class AppComponent {
106105
/**
107106
* Whether to show authorized content (navigation, header, e.g.)
108107
*/
109-
public readonly isAuthorized = toSignal(
110-
this.store.select(selectAuthTokenResponse).pipe(map((res) => !!res)),
108+
public readonly isAuthorized = this.store.selectSignal(
109+
selectAuthIsAuthorized,
111110
);
112111
/**
113112
* Side nav opened flag

frontend/src/app/entities/auth/state/auth.selectors.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ const _selectAuth = createFeatureSelector<IAuthState>('auth');
55
export const selectAuth = createSelector(_selectAuth, (state) => state);
66
export const selectAuthIsLoading = createSelector(
77
_selectAuth,
8-
(state) => state.isLoading
8+
(state) => state.isLoading,
99
);
1010
export const selectAuthTokenResponse = createSelector(
1111
_selectAuth,
12-
(state) => state.tokenResponse
12+
(state) => state.tokenResponse,
13+
);
14+
export const selectAuthIsAuthorized = createSelector(
15+
_selectAuth,
16+
(state) => !!state.tokenResponse,
1317
);

frontend/src/app/features/about/about.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { CodeExamplesComponent } from '../code-examples/code-examples.component'
1111
import { MatExpansionModule } from '@angular/material/expansion';
1212
import { ChangelogComponent } from 'src/app/shared/components/changelog/changelog.component';
1313
import { Store } from '@ngrx/store';
14-
import { toSignal } from '@angular/core/rxjs-interop';
1514
import { selectAppVersion } from 'src/app/state/app.selectors';
1615

1716
@Component({
@@ -34,5 +33,5 @@ import { selectAppVersion } from 'src/app/state/app.selectors';
3433
export class AboutComponent {
3534
private readonly store = inject(Store);
3635

37-
public readonly version = toSignal(this.store.select(selectAppVersion));
36+
public readonly version = this.store.selectSignal(selectAppVersion);
3837
}

frontend/src/app/features/admin/admin-status/admin-status.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { AsyncPipe, NgTemplateOutlet } from '@angular/common';
1+
import { NgTemplateOutlet } from '@angular/common';
22
import { Component, inject } from '@angular/core';
33
import { toSignal } from '@angular/core/rxjs-interop';
44
import { MatButton } from '@angular/material/button';
55
import { MatIcon } from '@angular/material/icon';
66
import { MatListModule } from '@angular/material/list';
77
import { TranslateModule, TranslateService } from '@ngx-translate/core';
8-
import { map, retry, catchError, of, share } from 'rxjs';
8+
import { map, retry, catchError, of } from 'rxjs';
99
import { SnackService } from 'src/app/core/services/snack.service';
1010
import { AdminApiService } from 'src/app/entities/admin/admin-api.service';
1111
import { PublicApiService } from 'src/app/entities/public/public-api.service';
@@ -16,7 +16,6 @@ import { PublicApiService } from 'src/app/entities/public/public-api.service';
1616
MatListModule,
1717
MatButton,
1818
MatIcon,
19-
AsyncPipe,
2019
TranslateModule,
2120
NgTemplateOutlet,
2221
],

frontend/src/app/features/admin/admin-user-dialog/admin-user-dialog.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
inject,
66
signal,
77
} from '@angular/core';
8-
import { toSignal } from '@angular/core/rxjs-interop';
98
import { FormsModule } from '@angular/forms';
109
import { MatButton } from '@angular/material/button';
1110
import {
@@ -62,7 +61,7 @@ export class AdminUserDialogComponent {
6261
private readonly translateService = inject(TranslateService);
6362
private readonly store = inject(Store);
6463

65-
public readonly isOwner = toSignal(this.store.select(selectUserIsOwner));
64+
public readonly isOwner = this.store.selectSignal(selectUserIsOwner);
6665
public readonly isLoading = signal(false);
6766

6867
public readonly EUserRole = EUserRole;

frontend/src/app/features/auth/auth.component.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
selectAppAllowRegistration,
2222
selectAppSmtpDisabled,
2323
} from 'src/app/state/app.selectors';
24-
import { toSignal } from '@angular/core/rxjs-interop';
2524
import { MatTooltip } from '@angular/material/tooltip';
2625

2726
@Component({
@@ -45,13 +44,11 @@ import { MatTooltip } from '@angular/material/tooltip';
4544
export class AuthComponent {
4645
private readonly store = inject(Store);
4746

48-
public readonly isLoading = toSignal(this.store.select(selectAuthIsLoading));
49-
public readonly allowRegistration = toSignal(
50-
this.store.select(selectAppAllowRegistration),
51-
);
52-
public readonly smtpDisabled = toSignal(
53-
this.store.select(selectAppSmtpDisabled),
47+
public readonly isLoading = this.store.selectSignal(selectAuthIsLoading);
48+
public readonly allowRegistration = this.store.selectSignal(
49+
selectAppAllowRegistration,
5450
);
51+
public readonly smtpDisabled = this.store.selectSignal(selectAppSmtpDisabled);
5552
public readonly form = new FormGroup<
5653
TInterfaceToForm<Omit<IOAuth2PasswordRequestForm, 'grant_type'>>
5754
>({

frontend/src/app/features/card/card.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ export class CardComponent implements OnInit, OnDestroy {
8484
private readonly destroyRef = inject(DestroyRef);
8585
private readonly matDialog = inject(MatDialog);
8686

87-
public readonly card = toSignal(this.store.select(selectCardsActiveInfo));
88-
public readonly isLoading = toSignal(this.store.select(selectCardsIsLoading));
89-
public readonly canDelete = toSignal(
90-
this.store.select(selectCardsActiveCanDelete),
87+
public readonly card = this.store.selectSignal(selectCardsActiveInfo);
88+
public readonly isLoading = this.store.selectSignal(selectCardsIsLoading);
89+
public readonly canDelete = this.store.selectSignal(
90+
selectCardsActiveCanDelete,
9191
);
92-
public readonly hasChanges = toSignal(
93-
this.store.select(selectCardsActiveHasChanges),
92+
public readonly hasChanges = this.store.selectSignal(
93+
selectCardsActiveHasChanges,
9494
);
9595

9696
public readonly form = new FormGroup<TInterfaceToForm<ICardBase>>({

frontend/src/app/features/cards/cards.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class CardsComponent {
7171
{ initialValue: this.router.url === '/cards' },
7272
);
7373
public readonly cardsPlaceholder = Array(6).fill(null);
74-
public readonly isLoading = toSignal(this.store.select(selectCardsIsLoading));
74+
public readonly isLoading = this.store.selectSignal(selectCardsIsLoading);
7575
/**
7676
* Form control for search field
7777
*/
@@ -80,7 +80,7 @@ export class CardsComponent {
8080
/**
8181
* All cards
8282
*/
83-
private readonly _cards = toSignal(this.store.select(selectCardsList));
83+
private readonly _cards = this.store.selectSignal(selectCardsList);
8484
/**
8585
* Search signal
8686
*/

frontend/src/app/features/user/user.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
selectUserIsOwner,
1313
} from 'src/app/entities/user/state/user.selectors';
1414
import { UserActions } from 'src/app/entities/user/state/user.actions';
15-
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
15+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1616
import {
1717
ReactiveFormsModule,
1818
FormGroup,
@@ -57,11 +57,9 @@ export class UserComponent implements OnInit {
5757
return this.form.value as IUserUpdate;
5858
}
5959

60-
public readonly isOwner = toSignal(this.store.select(selectUserIsOwner));
61-
public readonly isLoading = toSignal(this.store.select(selectUserIsLoading));
62-
public readonly hasChanges = toSignal(
63-
this.store.select(selectUserHasChanges),
64-
);
60+
public readonly isOwner = this.store.selectSignal(selectUserIsOwner);
61+
public readonly isLoading = this.store.selectSignal(selectUserIsLoading);
62+
public readonly hasChanges = this.store.selectSignal(selectUserHasChanges);
6563
public readonly hidePassword = signal(true);
6664
public readonly hideConfirmPassword = signal(true);
6765

0 commit comments

Comments
 (0)