Skip to content

refactor: expand private getter restrictions to underscored members #20083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cdk-experimental/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CdkDialogContainer extends BasePortalOutlet implements OnDestroy {
// @HostBinding is used in the class as it is expected to be extended. Since @Component decorator
// metadata is not inherited by child classes, instead the host binding data is defined in a way
// that can be inherited.
// tslint:disable:no-host-decorator-in-concrete
// tslint:disable:no-host-decorator-in-concrete no-private-getters
@HostBinding('attr.aria-label') get _ariaLabel() { return this._config.ariaLabel || null; }

@HostBinding('attr.aria-describedby')
Expand All @@ -98,7 +98,7 @@ export class CdkDialogContainer extends BasePortalOutlet implements OnDestroy {
@HostBinding('attr.aria-modal') _ariaModal: boolean = true;

@HostBinding('attr.tabindex') get _tabindex() { return -1; }
// tslint:disable:no-host-decorator-in-concrete
// tslint:disable:no-host-decorator-in-concrete no-private-getters

/** The portal host inside of this container into which the dialog content will be loaded. */
@ViewChild(CdkPortalOutlet, {static: true}) _portalHost: CdkPortalOutlet;
Expand Down
4 changes: 2 additions & 2 deletions src/cdk-experimental/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export class Dialog implements OnDestroy {
private _scrollStrategy: () => ScrollStrategy;

/** Stream that emits when all dialogs are closed. */
get _afterAllClosed(): Observable<void> {
_getAfterAllClosed(): Observable<void> {
return this._parentDialog ? this._parentDialog.afterAllClosed : this._afterAllClosedBase;
}
_afterAllClosedBase = new Subject<void>();

// TODO(jelbourn): tighten the type on the right-hand side of this expression.
afterAllClosed: Observable<void> = defer(() => this.openDialogs.length ?
this._afterAllClosed : this._afterAllClosed.pipe(startWith(undefined)));
this._getAfterAllClosed() : this._getAfterAllClosed().pipe(startWith(undefined)));

/** Stream that emits when a dialog is opened. */
get afterOpened(): Subject<DialogRef<any>> {
Expand Down
5 changes: 0 additions & 5 deletions src/cdk/overlay/position/connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ export class ConnectedPositionStrategy implements PositionStrategy {

private _direction: Direction | null;

/** Whether the we're dealing with an RTL context */
get _isRtl() {
return this._overlayRef.getDirection() === 'rtl';
}

/** Ordered list of preferred positions, from most to least desirable. */
_preferredPositions: ConnectionPositionPair[] = [];

Expand Down
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-chips/chip-grid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,12 @@ describe('MDC-based MatChipGrid', () => {
secondChip.focus();
fixture.detectChanges();

expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus)).toBe(1);
expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus())).toBe(1);

dispatchKeyboardEvent(secondChip, 'keydown', DELETE);
fixture.detectChanges();

expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus)).toBe(1);
expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus())).toBe(1);
});

describe('when the input has focus', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-chips/chip-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class MatChipOption extends MatChip implements AfterContentInit {
return;
}

if (!this._hasFocus) {
if (!this._hasFocus()) {
this._elementRef.nativeElement.focus();
this._onFocus.next({chip: this});
}
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-chips/chip-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class MatChipRow extends MatChip implements AfterContentInit, AfterViewIn
this._hasFocusInternal = false;
// Wait to see if focus moves to the other gridcell
setTimeout(() => {
if (this._hasFocus) {
if (this._hasFocus()) {
return;
}
this._onBlur.next({chip: this});
Expand Down
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-chips/chip-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit

/** Checks whether any of the chips is focused. */
protected _hasFocusedChip() {
return this._chips && this._chips.some(chip => chip._hasFocus);
return this._chips && this._chips.some(chip => chip._hasFocus());
}

/** Syncs the chip-set's state with the individual chips. */
Expand Down Expand Up @@ -251,7 +251,7 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
// In case the chip that will be removed is currently focused, we temporarily store
// the index in order to be able to determine an appropriate sibling chip that will
// receive focus.
if (this._isValidIndex(chipIndex) && chip._hasFocus) {
if (this._isValidIndex(chipIndex) && chip._hasFocus()) {
this._lastDestroyedChipIndex = chipIndex;
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
this._chipFoundation.handleTransitionEnd(event);
}

get _hasFocus() {
_hasFocus() {
return this._hasFocusInternal;
}

Expand Down
6 changes: 3 additions & 3 deletions src/material/datepicker/datepicker-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,16 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
id: string = `mat-datepicker-${datepickerUid++}`;

/** The minimum selectable date. */
get _minDate(): D | null {
_getMinDate(): D | null {
return this._datepickerInput && this._datepickerInput.min;
}

/** The maximum selectable date. */
get _maxDate(): D | null {
_getMaxDate(): D | null {
return this._datepickerInput && this._datepickerInput.max;
}

get _dateFilter(): DateFilterFn<D> {
_getDateFilter(): DateFilterFn<D> {
return this._datepickerInput && this._datepickerInput.dateFilter;
}

Expand Down
6 changes: 3 additions & 3 deletions src/material/datepicker/datepicker-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[ngClass]="datepicker.panelClass"
[startAt]="datepicker.startAt"
[startView]="datepicker.startView"
[minDate]="datepicker._minDate"
[maxDate]="datepicker._maxDate"
[dateFilter]="datepicker._dateFilter"
[minDate]="datepicker._getMinDate()"
[maxDate]="datepicker._getMaxDate()"
[dateFilter]="datepicker._getDateFilter()"
[headerComponent]="datepicker.calendarHeaderComponent"
[selected]="_getSelected()"
[dateClass]="datepicker.dateClass"
Expand Down
8 changes: 4 additions & 4 deletions src/material/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,8 @@ describe('MatDatepicker', () => {
}));

it('should use min and max dates specified by the input', () => {
expect(testComponent.datepicker._minDate).toEqual(new Date(2010, JAN, 1));
expect(testComponent.datepicker._maxDate).toEqual(new Date(2020, JAN, 1));
expect(testComponent.datepicker._getMinDate()).toEqual(new Date(2010, JAN, 1));
expect(testComponent.datepicker._getMaxDate()).toEqual(new Date(2020, JAN, 1));
});

it('should mark invalid when value is before min', fakeAsync(() => {
Expand All @@ -1283,15 +1283,15 @@ describe('MatDatepicker', () => {
}));

it('should not mark invalid when value equals min', fakeAsync(() => {
testComponent.date = testComponent.datepicker._minDate;
testComponent.date = testComponent.datepicker._getMinDate();
revalidate();

expect(fixture.debugElement.query(By.css('input'))!.nativeElement.classList)
.not.toContain('ng-invalid');
}));

it('should not mark invalid when value equals max', fakeAsync(() => {
testComponent.date = testComponent.datepicker._maxDate;
testComponent.date = testComponent.datepicker._getMaxDate();
revalidate();

expect(fixture.debugElement.query(By.css('input'))!.nativeElement.classList)
Expand Down
10 changes: 5 additions & 5 deletions src/material/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export class MatDialog implements OnDestroy {
return this._parentDialog ? this._parentDialog.afterOpened : this._afterOpenedAtThisLevel;
}

get _afterAllClosed(): Subject<void> {
_getAfterAllClosed(): Subject<void> {
const parent = this._parentDialog;
return parent ? parent._afterAllClosed : this._afterAllClosedAtThisLevel;
return parent ? parent._getAfterAllClosed() : this._afterAllClosedAtThisLevel;
}

// TODO (jelbourn): tighten the typing right-hand side of this expression.
Expand All @@ -96,8 +96,8 @@ export class MatDialog implements OnDestroy {
* Will emit on subscribe if there are no open dialogs to begin with.
*/
readonly afterAllClosed: Observable<void> = defer(() => this.openDialogs.length ?
this._afterAllClosed :
this._afterAllClosed.pipe(startWith(undefined))) as Observable<any>;
this._getAfterAllClosed() :
this._getAfterAllClosed().pipe(startWith(undefined))) as Observable<any>;

constructor(
private _overlay: Overlay,
Expand Down Expand Up @@ -324,7 +324,7 @@ export class MatDialog implements OnDestroy {
});

this._ariaHiddenElements.clear();
this._afterAllClosed.next();
this._getAfterAllClosed().next();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/material/form-field/form-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
[id]="_labelId"
[attr.for]="_control.id"
[attr.aria-owns]="_control.id"
[class.mat-empty]="_control.empty && !_shouldAlwaysFloat"
[class.mat-form-field-empty]="_control.empty && !_shouldAlwaysFloat"
[class.mat-empty]="_control.empty && !_shouldAlwaysFloat()"
[class.mat-form-field-empty]="_control.empty && !_shouldAlwaysFloat()"
[class.mat-accent]="color == 'accent'"
[class.mat-warn]="color == 'warn'"
#label
Expand Down
18 changes: 7 additions & 11 deletions src/material/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const MAT_FORM_FIELD = new InjectionToken<MatFormField>('MatFormField');
'[class.mat-form-field-appearance-outline]': 'appearance == "outline"',
'[class.mat-form-field-appearance-legacy]': 'appearance == "legacy"',
'[class.mat-form-field-invalid]': '_control.errorState',
'[class.mat-form-field-can-float]': '_canLabelFloat',
'[class.mat-form-field-can-float]': '_canLabelFloat()',
'[class.mat-form-field-should-float]': '_shouldLabelFloat()',
'[class.mat-form-field-has-label]': '_hasFloatingLabel()',
'[class.mat-form-field-hide-placeholder]': '_hideControlPlaceholder()',
Expand Down Expand Up @@ -199,12 +199,12 @@ export class MatFormField extends _MatFormFieldMixinBase
private _showAlwaysAnimate = false;

/** Whether the floating label should always float or not. */
get _shouldAlwaysFloat(): boolean {
_shouldAlwaysFloat(): boolean {
return this.floatLabel === 'always' && !this._showAlwaysAnimate;
}

/** Whether the label can float or not. */
get _canLabelFloat(): boolean { return this.floatLabel !== 'never'; }
_canLabelFloat(): boolean { return this.floatLabel !== 'never'; }

/** State of the mat-hint and mat-error animations. */
_subscriptAnimationState: string = '';
Expand Down Expand Up @@ -271,10 +271,6 @@ export class MatFormField extends _MatFormFieldMixinBase

@ContentChild(MatLabel) _labelChildNonStatic: MatLabel;
@ContentChild(MatLabel, {static: true}) _labelChildStatic: MatLabel;
get _labelChild() {
return this._labelChildNonStatic || this._labelChildStatic;
}

@ContentChild(MatPlaceholder) _placeholderChild: MatPlaceholder;

// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
Expand Down Expand Up @@ -407,12 +403,12 @@ export class MatFormField extends _MatFormFieldMixinBase
}

_hasLabel() {
return !!this._labelChild;
return !!(this._labelChildNonStatic || this._labelChildStatic);
}

_shouldLabelFloat() {
return this._canLabelFloat &&
((this._control && this._control.shouldLabelFloat) || this._shouldAlwaysFloat);
return this._canLabelFloat() &&
((this._control && this._control.shouldLabelFloat) || this._shouldAlwaysFloat());
}

_hideControlPlaceholder() {
Expand All @@ -434,7 +430,7 @@ export class MatFormField extends _MatFormFieldMixinBase

/** Animates the placeholder up and locks it in position. */
_animateAndLockLabel(): void {
if (this._hasFloatingLabel() && this._canLabelFloat) {
if (this._hasFloatingLabel() && this._canLabelFloat()) {
// If animations are disabled, we shouldn't go in here,
// because the `transitionend` will never fire.
if (this._animationsEnabled && this._label) {
Expand Down
4 changes: 2 additions & 2 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,15 @@ describe('MatInput without forms', () => {
inputContainer._animateAndLockLabel();
fixture.detectChanges();

expect(inputContainer._shouldAlwaysFloat).toBe(false);
expect(inputContainer._shouldAlwaysFloat()).toBe(false);
expect(inputContainer.floatLabel).toBe('always');

const fakeEvent = createFakeEvent('transitionend');
(fakeEvent as any).propertyName = 'transform';
label.dispatchEvent(fakeEvent);
fixture.detectChanges();

expect(inputContainer._shouldAlwaysFloat).toBe(true);
expect(inputContainer._shouldAlwaysFloat()).toBe(true);
expect(inputContainer.floatLabel).toBe('always');
}));

Expand Down
18 changes: 9 additions & 9 deletions src/material/progress-spinner/progress-spinner.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<svg
[style.width.px]="diameter"
[style.height.px]="diameter"
[attr.viewBox]="_viewBox"
[attr.viewBox]="_getViewBox()"
preserveAspectRatio="xMidYMid meet"
focusable="false"
[ngSwitch]="mode === 'indeterminate'">
Expand All @@ -24,18 +24,18 @@
*ngSwitchCase="true"
cx="50%"
cy="50%"
[attr.r]="_circleRadius"
[attr.r]="_getCircleRadius()"
[style.animation-name]="'mat-progress-spinner-stroke-rotate-' + diameter"
[style.stroke-dashoffset.px]="_strokeDashOffset"
[style.stroke-dasharray.px]="_strokeCircumference"
[style.stroke-width.%]="_circleStrokeWidth"></circle>
[style.stroke-dashoffset.px]="_getStrokeDashOffset()"
[style.stroke-dasharray.px]="_getStrokeCircumference()"
[style.stroke-width.%]="_getCircleStrokeWidth()"></circle>

<circle
*ngSwitchCase="false"
cx="50%"
cy="50%"
[attr.r]="_circleRadius"
[style.stroke-dashoffset.px]="_strokeDashOffset"
[style.stroke-dasharray.px]="_strokeCircumference"
[style.stroke-width.%]="_circleStrokeWidth"></circle>
[attr.r]="_getCircleRadius()"
[style.stroke-dashoffset.px]="_getStrokeDashOffset()"
[style.stroke-dasharray.px]="_getStrokeCircumference()"
[style.stroke-width.%]="_getCircleStrokeWidth()"></circle>
</svg>
23 changes: 12 additions & 11 deletions src/material/progress-spinner/progress-spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,37 +230,37 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
}

/** The radius of the spinner, adjusted for stroke width. */
get _circleRadius() {
_getCircleRadius() {
return (this.diameter - BASE_STROKE_WIDTH) / 2;
}

/** The view box of the spinner's svg element. */
get _viewBox() {
const viewBox = this._circleRadius * 2 + this.strokeWidth;
_getViewBox() {
const viewBox = this._getCircleRadius() * 2 + this.strokeWidth;
return `0 0 ${viewBox} ${viewBox}`;
}

/** The stroke circumference of the svg circle. */
get _strokeCircumference(): number {
return 2 * Math.PI * this._circleRadius;
_getStrokeCircumference(): number {
return 2 * Math.PI * this._getCircleRadius();
}

/** The dash offset of the svg circle. */
get _strokeDashOffset() {
_getStrokeDashOffset() {
if (this.mode === 'determinate') {
return this._strokeCircumference * (100 - this._value) / 100;
return this._getStrokeCircumference() * (100 - this._value) / 100;
}

// In fallback mode set the circle to 80% and rotate it with CSS.
if (this._fallbackAnimation && this.mode === 'indeterminate') {
return this._strokeCircumference * 0.2;
return this._getStrokeCircumference() * 0.2;
}

return null;
}

/** Stroke width of the circle in percent. */
get _circleStrokeWidth() {
_getCircleStrokeWidth() {
return this.strokeWidth / this.diameter * 100;
}

Expand Down Expand Up @@ -288,10 +288,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements

/** Generates animation styles adjusted for the spinner's diameter. */
private _getAnimationText(): string {
const strokeCircumference = this._getStrokeCircumference();
return INDETERMINATE_ANIMATION_TEMPLATE
// Animation should begin at 5% and end at 80%
.replace(/START_VALUE/g, `${0.95 * this._strokeCircumference}`)
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`)
.replace(/START_VALUE/g, `${0.95 * strokeCircumference}`)
.replace(/END_VALUE/g, `${0.2 * strokeCircumference}`)
.replace(/DIAMETER/g, `${this.diameter}`);
}

Expand Down
Loading