Skip to content

Commit dddf283

Browse files
committed
refactor(multiple): fix initializers using constructor members
Fixes the cases where the initializers of properties were referencing members initialized in the constructor. This was preventing compatibility with `useDefineForClassFields`.
1 parent 1abb484 commit dddf283

File tree

9 files changed

+29
-15
lines changed

9 files changed

+29
-15
lines changed

src/cdk-experimental/column-resize/column-resize-notifier.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable} from '@angular/core';
9+
import {inject, Injectable} from '@angular/core';
1010
import {Observable, Subject} from 'rxjs';
1111

1212
/** Indicates the width of a column. */
@@ -55,11 +55,11 @@ export class ColumnResizeNotifierSource {
5555
/** Service for triggering column resizes imperatively or being notified of them. */
5656
@Injectable()
5757
export class ColumnResizeNotifier {
58+
private readonly _source = inject(ColumnResizeNotifierSource);
59+
5860
/** Emits whenever a column is resized. */
5961
readonly resizeCompleted: Observable<ColumnSize> = this._source.resizeCompleted;
6062

61-
constructor(private readonly _source: ColumnResizeNotifierSource) {}
62-
6363
/** Instantly resizes the specified column. */
6464
resize(columnId: string, size: number): void {
6565
this._source.triggerResize.next({

src/cdk/platform/platform.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Inject, Injectable, PLATFORM_ID} from '@angular/core';
9+
import {inject, Injectable, PLATFORM_ID} from '@angular/core';
1010
import {isPlatformBrowser} from '@angular/common';
1111

1212
// Whether the current platform supports the V8 Break Iterator. The V8 check
@@ -30,6 +30,8 @@ try {
3030
*/
3131
@Injectable({providedIn: 'root'})
3232
export class Platform {
33+
private _platformId = inject(PLATFORM_ID);
34+
3335
// We want to use the Angular platform check because if the Document is shimmed
3436
// without the navigator, the following checks will fail. This is preferred because
3537
// sometimes the Document may be shimmed without the user's knowledge or intention
@@ -84,5 +86,8 @@ export class Platform {
8486
/** Whether the current browser is Safari. */
8587
SAFARI: boolean = this.isBrowser && /safari/i.test(navigator.userAgent) && this.WEBKIT;
8688

87-
constructor(@Inject(PLATFORM_ID) private _platformId: Object) {}
89+
/** Backwards-compatible constructor. */
90+
constructor(..._args: unknown[]);
91+
92+
constructor() {}
8893
}

src/cdk/testing/testbed/task-state-zone-interceptor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type PatchedProxyZone = ProxyZone & {
3030
* This serves as a workaround for https://github.com/angular/angular/issues/32896.
3131
*/
3232
export class TaskStateZoneInterceptor {
33+
private _lastState: HasTaskState | null = null;
34+
3335
/** Subject that can be used to emit a new state change. */
3436
private readonly _stateSubject = new BehaviorSubject<TaskState>(
3537
this._lastState ? this._getTaskStateFromInternalZoneState(this._lastState) : {stable: true},
@@ -38,7 +40,9 @@ export class TaskStateZoneInterceptor {
3840
/** Public observable that emits whenever the task state changes. */
3941
readonly state: Observable<TaskState> = this._stateSubject;
4042

41-
constructor(private _lastState: HasTaskState | null) {}
43+
constructor(lastState: HasTaskState | null) {
44+
this._lastState = lastState;
45+
}
4246

4347
/** This will be called whenever the task state changes in the intercepted zone. */
4448
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) {

src/material-experimental/selection/row-selection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ import {Input, Directive} from '@angular/core';
2828
})
2929
export class MatRowSelection<T> extends CdkRowSelection<T> {
3030
/** The value that is associated with the row */
31-
@Input('matRowSelectionValue') override value: T;
31+
@Input('matRowSelectionValue') override value: T = undefined!;
3232
}

src/material/dialog/dialog-container.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Optional,
2222
ViewEncapsulation,
2323
ANIMATION_MODULE_TYPE,
24+
inject,
2425
} from '@angular/core';
2526
import {MatDialogConfig} from './dialog-config';
2627
import {CdkDialogContainer} from '@angular/cdk/dialog';
@@ -72,6 +73,8 @@ export const CLOSE_ANIMATION_DURATION = 75;
7273
},
7374
})
7475
export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> implements OnDestroy {
76+
private _animationMode = inject(ANIMATION_MODULE_TYPE, {optional: true});
77+
7578
/** Emits when an animation state changes. */
7679
_animationStateChanged = new EventEmitter<LegacyDialogAnimationEvent>();
7780

@@ -102,7 +105,7 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
102105
interactivityChecker: InteractivityChecker,
103106
ngZone: NgZone,
104107
overlayRef: OverlayRef,
105-
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string,
108+
@Optional() @Inject(ANIMATION_MODULE_TYPE) _unusedAnimationMode?: string,
106109
focusMonitor?: FocusMonitor,
107110
) {
108111
super(

src/material/select/select.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ export class MatSelect
217217
ControlValueAccessor,
218218
MatFormFieldControl<any>
219219
{
220+
protected _defaultOptions = inject(MAT_SELECT_CONFIG, {optional: true});
221+
220222
/** All of the defined select options. */
221223
@ContentChildren(MatOption, {descendants: true}) options: QueryList<MatOption>;
222224

@@ -607,7 +609,7 @@ export class MatSelect
607609
@Attribute('tabindex') tabIndex: string,
608610
@Inject(MAT_SELECT_SCROLL_STRATEGY) scrollStrategyFactory: any,
609611
private _liveAnnouncer: LiveAnnouncer,
610-
@Optional() @Inject(MAT_SELECT_CONFIG) protected _defaultOptions?: MatSelectConfig,
612+
@Optional() @Inject(MAT_SELECT_CONFIG) _unusedDefaultOptions?: unknown,
611613
) {
612614
if (this.ngControl) {
613615
// Note: we provide the value accessor through here, instead of
@@ -617,8 +619,8 @@ export class MatSelect
617619

618620
// Note that we only want to set this when the defaults pass it in, otherwise it should
619621
// stay as `undefined` so that it falls back to the default in the key manager.
620-
if (_defaultOptions?.typeaheadDebounceInterval != null) {
621-
this.typeaheadDebounceInterval = _defaultOptions.typeaheadDebounceInterval;
622+
if (this._defaultOptions?.typeaheadDebounceInterval != null) {
623+
this.typeaheadDebounceInterval = this._defaultOptions.typeaheadDebounceInterval;
622624
}
623625

624626
this._errorStateTracker = new _ErrorStateTracker(

tools/public_api_guard/cdk/platform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function normalizePassiveListenerOptions(options: AddEventListenerOptions
2929

3030
// @public
3131
export class Platform {
32-
constructor(_platformId: Object);
32+
constructor(..._args: unknown[]);
3333
ANDROID: boolean;
3434
BLINK: boolean;
3535
EDGE: boolean;

tools/public_api_guard/material/dialog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class MatDialogConfig<D = any> {
188188

189189
// @public (undocumented)
190190
export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> implements OnDestroy {
191-
constructor(elementRef: ElementRef, focusTrapFactory: FocusTrapFactory, _document: any, dialogConfig: MatDialogConfig, interactivityChecker: InteractivityChecker, ngZone: NgZone, overlayRef: OverlayRef, _animationMode?: string | undefined, focusMonitor?: FocusMonitor);
191+
constructor(elementRef: ElementRef, focusTrapFactory: FocusTrapFactory, _document: any, dialogConfig: MatDialogConfig, interactivityChecker: InteractivityChecker, ngZone: NgZone, overlayRef: OverlayRef, _unusedAnimationMode?: string, focusMonitor?: FocusMonitor);
192192
protected _actionSectionCount: number;
193193
_animationsEnabled: boolean;
194194
_animationStateChanged: EventEmitter<LegacyDialogAnimationEvent>;

tools/public_api_guard/material/select.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export { MatPrefix }
8787
// @public (undocumented)
8888
export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit, DoCheck, ControlValueAccessor, MatFormFieldControl<any> {
8989
constructor(_viewportRuler: ViewportRuler, _changeDetectorRef: ChangeDetectorRef,
90-
_unusedNgZone: NgZone, defaultErrorStateMatcher: ErrorStateMatcher, _elementRef: ElementRef, _dir: Directionality, parentForm: NgForm, parentFormGroup: FormGroupDirective, _parentFormField: MatFormField, ngControl: NgControl, tabIndex: string, scrollStrategyFactory: any, _liveAnnouncer: LiveAnnouncer, _defaultOptions?: MatSelectConfig | undefined);
90+
_unusedNgZone: NgZone, defaultErrorStateMatcher: ErrorStateMatcher, _elementRef: ElementRef, _dir: Directionality, parentForm: NgForm, parentFormGroup: FormGroupDirective, _parentFormField: MatFormField, ngControl: NgControl, tabIndex: string, scrollStrategyFactory: any, _liveAnnouncer: LiveAnnouncer, _unusedDefaultOptions?: unknown);
9191
ariaLabel: string;
9292
ariaLabelledby: string;
9393
protected _canOpen(): boolean;
@@ -100,7 +100,7 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
100100
controlType: string;
101101
customTrigger: MatSelectTrigger;
102102
// (undocumented)
103-
protected _defaultOptions?: MatSelectConfig | undefined;
103+
protected _defaultOptions: MatSelectConfig | null;
104104
protected readonly _destroy: Subject<void>;
105105
readonly disableAutomaticLabeling = true;
106106
disabled: boolean;

0 commit comments

Comments
 (0)