diff --git a/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts b/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts index 2050e742cf..b18a12946f 100644 --- a/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts +++ b/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts @@ -1,46 +1,20 @@ -import { Pipe, PipeTransform, OnDestroy } from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import { Store } from '@ngxs/store'; +import { Config } from '../models'; import { ConfigState } from '../states'; -import { takeUntilDestroy } from '../utils'; -import { distinctUntilChanged, takeUntil } from 'rxjs/operators'; -import { Subject } from 'rxjs'; @Pipe({ name: 'abpLocalization', - // tslint:disable-next-line: no-pipe-impure - pure: false // required to update the value }) -export class LocalizationPipe implements PipeTransform, OnDestroy { - initialValue = ''; - - value: string; - - destroy$ = new Subject(); - +export class LocalizationPipe implements PipeTransform { constructor(private store: Store) {} - transform(value: string = '', ...interpolateParams: string[]): string { - if (this.initialValue !== value) { - this.initialValue = value; - this.destroy$.next(); - - this.store - .select( - ConfigState.getCopy( - value, - ...interpolateParams.reduce((acc, val) => (Array.isArray(val) ? [...acc, ...val] : [...acc, val]), []) - ) - ) - .pipe( - takeUntil(this.destroy$), - takeUntilDestroy(this), - distinctUntilChanged() - ) - .subscribe(copy => (this.value = copy)); - } - - return this.value; + transform(value: string | Config.LocalizationWithDefault = '', ...interpolateParams: string[]): string { + return this.store.selectSnapshot( + ConfigState.getLocalization( + value, + ...interpolateParams.reduce((acc, val) => (Array.isArray(val) ? [...acc, ...val] : [...acc, val]), []), + ), + ); } - - ngOnDestroy() {} } diff --git a/npm/ng-packs/packages/core/src/lib/states/session.state.ts b/npm/ng-packs/packages/core/src/lib/states/session.state.ts index 0754b0d62b..544bd42b2b 100644 --- a/npm/ng-packs/packages/core/src/lib/states/session.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/session.state.ts @@ -4,6 +4,7 @@ import { ABP, Session } from '../models'; import { GetAppConfiguration } from '../actions/config.actions'; import { LocalizationService } from '../services/localization.service'; import { from, combineLatest } from 'rxjs'; +import { switchMap } from 'rxjs/operators'; @State({ name: 'SessionState', @@ -28,7 +29,9 @@ export class SessionState { language: payload, }); - return combineLatest([dispatch(new GetAppConfiguration()), from(this.localizationService.registerLocale(payload))]); + return dispatch(new GetAppConfiguration()).pipe( + switchMap(() => from(this.localizationService.registerLocale(payload))), + ); } @Action(SetTenant)