Skip to content

Commit

Permalink
refactor!: remove redundant exports of internal functions (reduction …
Browse files Browse the repository at this point in the history
…of public API) (#2253)
  • Loading branch information
nsbarsukov authored and splincode committed Aug 1, 2022
1 parent 2d0cebf commit 330dd3f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
import {TuiHintMode, TuiSizeL, TuiSizeS} from '@taiga-ui/core';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function valueAssertion(value: ReadonlyArray<readonly number[]>): boolean {
function valueAssertion(value: ReadonlyArray<readonly number[]>): boolean {
const valid = value.every(array => array.length === value[0].length);

return valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ import {distinctUntilChanged} from 'rxjs/operators';

import {TuiLineChartHintDirective} from './line-chart-hint.directive';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function smoothingAssertion(smoothingFactor: number): boolean {
return tuiInRange(smoothingFactor, 0, 100);
}

const SMOOTHING_MESSAGE = `smoothingFactor must be between 0 and 100`;

@Component({
selector: `tui-line-chart`,
templateUrl: `./line-chart.template.html`,
Expand Down Expand Up @@ -66,7 +59,10 @@ export class TuiLineChartComponent {
height = 0;

@Input()
@tuiDefaultProp(smoothingAssertion, SMOOTHING_MESSAGE)
@tuiDefaultProp(
(smoothingFactor: number) => tuiInRange(smoothingFactor, 0, 100),
`smoothingFactor must be between 0 and 100`,
)
smoothingFactor = 0;

@Input()
Expand Down
12 changes: 4 additions & 8 deletions projects/addon-commerce/components/card/card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import {TuiPaymentSystem} from '@taiga-ui/addon-commerce/types';
import {tuiDefaultProp} from '@taiga-ui/cdk';
import {TuiSizeS} from '@taiga-ui/core';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function cardNumberAssertion({length}: string): boolean {
return !length || length === 4;
}

export const cardNumberAssertionMessage = `cardNumber should contain 4 symbols`;

const icons: Record<TuiPaymentSystem, string> = {
mir: `tuiIconMirMono`,
visa: `tuiIconVisaMono`,
Expand All @@ -35,7 +28,10 @@ export class TuiCardComponent {
brandLogo = ``;

@Input()
@tuiDefaultProp(cardNumberAssertion, cardNumberAssertionMessage)
@tuiDefaultProp(
({length}: string) => !length || length === 4,
`cardNumber should contain 4 symbols`,
)
cardNumber = ``;

@Input()
Expand Down
16 changes: 5 additions & 11 deletions projects/cdk/directives/media/media.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import {
} from '@angular/core';
import {tuiDefaultProp, tuiRequiredSetter} from '@taiga-ui/cdk/decorators';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function nonNegativeFiniteAssertion(value: number): boolean {
return isFinite(value) && value >= 0;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export function volumeAssertion(volume: number): boolean {
return isFinite(volume) && volume >= 0 && volume <= 1;
}

@Directive({
selector: `video[tuiMedia], audio[tuiMedia]`,
exportAs: `tuiMedia`,
Expand All @@ -29,7 +19,7 @@ export class TuiMediaDirective {

@Input()
@HostBinding(`volume`)
@tuiDefaultProp(volumeAssertion)
@tuiDefaultProp((volume: number) => isFinite(volume) && volume >= 0 && volume <= 1)
volume = 1;

@Input(`playbackRate`)
Expand Down Expand Up @@ -111,3 +101,7 @@ export class TuiMediaDirective {
this.elementRef.nativeElement.playbackRate = this.playbackRate;
}
}

function nonNegativeFiniteAssertion(value: number): boolean {
return isFinite(value) && value >= 0;
}
9 changes: 4 additions & 5 deletions projects/kit/components/pagination/pagination.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ import {Observable} from 'rxjs';
const DOTS_LENGTH = 1;
const ACTIVE_ITEM_LENGTH = 1;

// eslint-disable-next-line @typescript-eslint/naming-convention
export function nonNegativeInteger(length: number): boolean {
return Number.isInteger(length) && length >= 0;
}

@Component({
selector: `tui-pagination`,
templateUrl: `./pagination.template.html`,
Expand Down Expand Up @@ -333,3 +328,7 @@ export class TuiPaginationComponent
this.indexChange.emit(index);
}
}

function nonNegativeInteger(length: number): boolean {
return Number.isInteger(length) && length >= 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ import {ChangeDetectionStrategy, Component, HostBinding, Input} from '@angular/c
import {tuiDefaultProp, tuiIsString} from '@taiga-ui/cdk';
import {TuiSizeS} from '@taiga-ui/core';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function nonNegativeInt(value: number): boolean {
return Number.isInteger(value) && value >= 0;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export function positiveInt(value: number): boolean {
return Number.isInteger(value) && value > 0;
}

@Component({
selector: `tui-progress-segmented`,
templateUrl: `./progress-segmented.template.html`,
Expand All @@ -20,11 +10,17 @@ export function positiveInt(value: number): boolean {
})
export class TuiProgressSegmentedComponent {
@Input()
@tuiDefaultProp(nonNegativeInt, `Must be non-negative integer between 0 and max`)
@tuiDefaultProp(
(value: number) => Number.isInteger(value) && value >= 0,
`Must be non-negative integer between 0 and max`,
)
value = 0;

@Input()
@tuiDefaultProp(positiveInt, `Must be positive integer`)
@tuiDefaultProp(
(value: number) => Number.isInteger(value) && value > 0,
`Must be positive integer`,
)
max = 1;

@Input()
Expand Down

0 comments on commit 330dd3f

Please sign in to comment.