mirror of https://github.com/abpframework/abp.git
2 changed files with 14 additions and 37 deletions
@ -1,46 +1,20 @@ |
|||||
import { Pipe, PipeTransform, OnDestroy } from '@angular/core'; |
import { Pipe, PipeTransform } from '@angular/core'; |
||||
import { Store } from '@ngxs/store'; |
import { Store } from '@ngxs/store'; |
||||
|
import { Config } from '../models'; |
||||
import { ConfigState } from '../states'; |
import { ConfigState } from '../states'; |
||||
import { takeUntilDestroy } from '../utils'; |
|
||||
import { distinctUntilChanged, takeUntil } from 'rxjs/operators'; |
|
||||
import { Subject } from 'rxjs'; |
|
||||
|
|
||||
@Pipe({ |
@Pipe({ |
||||
name: 'abpLocalization', |
name: 'abpLocalization', |
||||
// tslint:disable-next-line: no-pipe-impure
|
|
||||
pure: false // required to update the value
|
|
||||
}) |
}) |
||||
export class LocalizationPipe implements PipeTransform, OnDestroy { |
export class LocalizationPipe implements PipeTransform { |
||||
initialValue = ''; |
|
||||
|
|
||||
value: string; |
|
||||
|
|
||||
destroy$ = new Subject(); |
|
||||
|
|
||||
constructor(private store: Store) {} |
constructor(private store: Store) {} |
||||
|
|
||||
transform(value: string = '', ...interpolateParams: string[]): string { |
transform(value: string | Config.LocalizationWithDefault = '', ...interpolateParams: string[]): string { |
||||
if (this.initialValue !== value) { |
return this.store.selectSnapshot( |
||||
this.initialValue = value; |
ConfigState.getLocalization( |
||||
this.destroy$.next(); |
value, |
||||
|
...interpolateParams.reduce((acc, val) => (Array.isArray(val) ? [...acc, ...val] : [...acc, val]), []), |
||||
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; |
|
||||
} |
} |
||||
|
|
||||
ngOnDestroy() {} |
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue