diff --git a/src/lib/misc/hidden-action/hidden-action.component.ts b/src/lib/misc/hidden-action/hidden-action.component.ts index 0447279..c379b72 100644 --- a/src/lib/misc/hidden-action/hidden-action.component.ts +++ b/src/lib/misc/hidden-action/hidden-action.component.ts @@ -1,9 +1,10 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; @Component({ selector: 'iqser-hidden-action', templateUrl: './hidden-action.component.html', - styleUrls: ['./hidden-action.component.scss'] + styleUrls: ['./hidden-action.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush }) export class HiddenActionComponent { @Input() requiredClicks = 4; diff --git a/src/lib/utils/functions.ts b/src/lib/utils/functions.ts index ebb6d58..1ad6bd7 100644 --- a/src/lib/utils/functions.ts +++ b/src/lib/utils/functions.ts @@ -18,10 +18,10 @@ export function humanize(value: string, lowercase = true): string { export const log = tap(console.log); -export const toNumber = (str: string) => { +export function toNumber(str: string): number { try { return parseInt(`${str}`.replace(/\D/g, ''), 10); } catch (e) { return 0; } -}; +} diff --git a/src/lib/utils/pruning-translation-loader.ts b/src/lib/utils/pruning-translation-loader.ts index 55a8b07..3ec063c 100644 --- a/src/lib/utils/pruning-translation-loader.ts +++ b/src/lib/utils/pruning-translation-loader.ts @@ -3,26 +3,27 @@ import { TranslateLoader } from '@ngx-translate/core'; import { map } from 'rxjs/operators'; import { Observable } from 'rxjs'; +interface T { + [key: string]: string | T; +} + export class PruningTranslationLoader implements TranslateLoader { constructor(private _http: HttpClient, private _prefix: string, private _suffix: string) {} - getTranslation(lang: string): Observable> { - return this._http - .get(`${this._prefix}${lang}${this._suffix}`) - .pipe(map((result: Record) => this._process(result))); + getTranslation(lang: string): Observable { + return this._http.get(`${this._prefix}${lang}${this._suffix}`).pipe(map(result => this._process(result as T))); } - private _process(object: unknown): Record { + private _process(object: T): T { return ( Object.keys(object) // eslint-disable-next-line no-prototype-builtins .filter(key => object.hasOwnProperty(key) && object[key] !== '') .reduce( - (result: Record, key) => ( - (result[key] = typeof object[key] === 'object' ? this._process(object[key]) : object[key]), - result + (result: T, key) => ( + (result[key] = typeof object[key] === 'object' ? this._process(object[key] as T) : object[key]), result ), - {}, + {} ) ); }