Skip to content

Commit 4a3ca82

Browse files
rafaelss95mmalerba
andauthored
refactor: make all event emitters readonly (#17666)
* refactor(material/core): make all event emitters readonly * fixup! refactor(material/core): make all event emitters readonly Co-authored-by: Miles Malerba <[email protected]>
1 parent 7b7c1cf commit 4a3ca82

File tree

124 files changed

+531
-587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+531
-587
lines changed

guides/bidirectionality.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class MyCustomComponent {
3131
this.dir = directionality.value;
3232

3333
directionality.change.subscribe(() => {
34-
this.dir = directionality.value;
34+
this.dir = directionality.value;
3535
});
3636
}
3737
}

src/cdk-experimental/dialog/dialog-container.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,19 @@ export class CdkDialogContainer extends BasePortalOutlet implements OnDestroy {
104104
@ViewChild(CdkPortalOutlet, {static: true}) _portalHost: CdkPortalOutlet;
105105

106106
/** A subject emitting before the dialog enters the view. */
107-
_beforeEnter: Subject<void> = new Subject();
107+
readonly _beforeEnter = new Subject<void>();
108108

109109
/** A subject emitting after the dialog enters the view. */
110-
_afterEnter: Subject<void> = new Subject();
110+
readonly _afterEnter = new Subject<void>();
111111

112112
/** A subject emitting before the dialog exits the view. */
113-
_beforeExit: Subject<void> = new Subject();
113+
readonly _beforeExit = new Subject<void>();
114114

115115
/** A subject emitting after the dialog exits the view. */
116-
_afterExit: Subject<void> = new Subject();
116+
readonly _afterExit = new Subject<void>();
117117

118118
/** Stream of animation `done` events. */
119-
_animationDone = new Subject<AnimationEvent>();
119+
readonly _animationDone = new Subject<AnimationEvent>();
120120

121121
constructor(
122122
private _elementRef: ElementRef<HTMLElement>,

src/cdk-experimental/dialog/dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class Dialog implements OnDestroy {
5454
_getAfterAllClosed(): Observable<void> {
5555
return this._parentDialog ? this._parentDialog.afterAllClosed : this._afterAllClosedBase;
5656
}
57-
_afterAllClosedBase = new Subject<void>();
57+
readonly _afterAllClosedBase = new Subject<void>();
5858

5959
// TODO(jelbourn): tighten the type on the right-hand side of this expression.
6060
afterAllClosed: Observable<void> = defer(() => this.openDialogs.length ?
@@ -64,7 +64,7 @@ export class Dialog implements OnDestroy {
6464
get afterOpened(): Subject<DialogRef<any>> {
6565
return this._parentDialog ? this._parentDialog.afterOpened : this._afterOpened;
6666
}
67-
_afterOpened: Subject<DialogRef<any>> = new Subject();
67+
readonly _afterOpened = new Subject<DialogRef<any>>();
6868

6969
/** Stream that emits when a dialog is opened. */
7070
get openDialogs(): DialogRef<any>[] {

src/cdk-experimental/listbox/listbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightab
9393
this._value = value;
9494
}
9595

96-
@Output() readonly selectionChange: EventEmitter<OptionSelectionChangeEvent<T>> =
96+
@Output() readonly selectionChange =
9797
new EventEmitter<OptionSelectionChangeEvent<T>>();
9898

9999
constructor(private readonly _elementRef: ElementRef,
@@ -243,7 +243,7 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
243243

244244
@ContentChildren(CdkOption, {descendants: true}) _options: QueryList<CdkOption<T>>;
245245

246-
@Output() readonly selectionChange: EventEmitter<ListboxSelectionChangeEvent<T>> =
246+
@Output() readonly selectionChange =
247247
new EventEmitter<ListboxSelectionChangeEvent<T>>();
248248

249249
@Input() id = `cdk-listbox-${listboxId++}`;

src/cdk-experimental/menu/context-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class CdkContextMenuTrigger implements OnDestroy {
129129
private _panelContent: TemplatePortal;
130130

131131
/** Emits when the element is destroyed. */
132-
private readonly _destroyed: Subject<void> = new Subject();
132+
private readonly _destroyed = new Subject<void>();
133133

134134
/** The menu stack for this trigger and its associated menus. */
135135
private readonly _menuStack = new MenuStack();

src/cdk-experimental/menu/menu-item-selectable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ let nextId = 0;
2020
@Directive()
2121
export abstract class CdkMenuItemSelectable extends CdkMenuItem {
2222
/** Event emitted when the selectable item is clicked */
23-
@Output('cdkMenuItemToggled') toggled: EventEmitter<CdkMenuItemSelectable> = new EventEmitter();
23+
@Output('cdkMenuItemToggled') readonly toggled: EventEmitter<CdkMenuItemSelectable> =
24+
new EventEmitter();
2425

2526
/** Whether the element is checked */
2627
@Input()

src/cdk-experimental/menu/menu-item.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class CdkMenuItem implements FocusableOption, FocusableElement, Toggler,
7070
* If this MenuItem is a regular MenuItem, outputs when it is triggered by a keyboard or mouse
7171
* event.
7272
*/
73-
@Output('cdkMenuItemTriggered') triggered: EventEmitter<void> = new EventEmitter();
73+
@Output('cdkMenuItemTriggered') readonly triggered: EventEmitter<void> = new EventEmitter();
7474

7575
/**
7676
* The tabindex for this menu item managed internally and used for implementing roving a
@@ -79,7 +79,7 @@ export class CdkMenuItem implements FocusableOption, FocusableElement, Toggler,
7979
_tabindex: 0 | -1 = -1;
8080

8181
/** Emits when the menu item is destroyed. */
82-
private readonly _destroyed: Subject<void> = new Subject();
82+
private readonly _destroyed = new Subject<void>();
8383

8484
constructor(
8585
readonly _elementRef: ElementRef<HTMLElement>,

src/cdk-experimental/popover-edit/focus-escape-notifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const enum FocusEscapeNotifierDirection {
2222
* focus leaves the region.
2323
*/
2424
export class FocusEscapeNotifier extends FocusTrap {
25-
private _escapeSubject = new Subject<FocusEscapeNotifierDirection>();
25+
private readonly _escapeSubject = new Subject<FocusEscapeNotifierDirection>();
2626

2727
constructor(
2828
element: HTMLElement,

src/cdk-experimental/popover-edit/lens-directives.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class CdkEditControl<FormValue> implements OnDestroy, OnInit {
8484
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
8585
// to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
8686
// can move this back into `host`.
87-
// tslint:disable:no-host-decorator-in-concrete
87+
// tslint:disable-next-line:no-host-decorator-in-concrete
8888
@HostListener('ngSubmit')
8989
handleFormSubmit(): void {
9090
if (this.ignoreSubmitUnlessValid && !this.editRef.isValid()) { return; }
@@ -107,7 +107,7 @@ export class CdkEditControl<FormValue> implements OnDestroy, OnInit {
107107
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
108108
// to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
109109
// can move this back into `host`.
110-
// tslint:disable:no-host-decorator-in-concrete
110+
// tslint:disable-next-line:no-host-decorator-in-concrete
111111
@HostListener('document:click', ['$event'])
112112
handlePossibleClickOut(evt: Event): void {
113113
if (closest(evt.target, EDIT_PANE_SELECTOR)) { return; }
@@ -128,7 +128,7 @@ export class CdkEditControl<FormValue> implements OnDestroy, OnInit {
128128
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
129129
// to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
130130
// can move this back into `host`.
131-
// tslint:disable:no-host-decorator-in-concrete
131+
// tslint:disable-next-line:no-host-decorator-in-concrete
132132
@HostListener('keydown', ['$event'])
133133
_handleKeydown(event: KeyboardEvent) {
134134
if (event.key === 'Escape' && !hasModifierKey(event)) {
@@ -167,7 +167,7 @@ export class CdkEditRevert<FormValue> {
167167
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
168168
// to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
169169
// can move this back into `host`.
170-
// tslint:disable:no-host-decorator-in-concrete
170+
// tslint:disable-next-line:no-host-decorator-in-concrete
171171
@HostListener('click')
172172
revertEdit(): void {
173173
this.editRef.reset();
@@ -192,10 +192,8 @@ export class CdkEditClose<FormValue> {
192192
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
193193
// to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
194194
// can move this back into `host`.
195-
// tslint:disable:no-host-decorator-in-concrete
196-
@HostListener('click')
197-
@HostListener('keydown.enter')
198-
@HostListener('keydown.space')
195+
// tslint:disable-next-line:no-host-decorator-in-concrete
196+
@HostListener('click') @HostListener('keydown.enter') @HostListener('keydown.space')
199197
closeEdit(): void {
200198
// Note that we use `click` here, rather than a keyboard event, because some screen readers
201199
// will emit a fake click event instead of an enter keyboard event on buttons. For the keyboard

src/cdk-experimental/popover-edit/table-directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ export class CdkEditOpen {
501501
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
502502
// to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
503503
// can move this back into `host`.
504-
// tslint:disable:no-host-decorator-in-concrete
504+
// tslint:disable-next-line:no-host-decorator-in-concrete
505505
@HostListener('click', ['$event'])
506506
openEdit(evt: Event): void {
507507
this.editEventDispatcher.editing.next(closest(this.elementRef.nativeElement!, CELL_SELECTOR));

0 commit comments

Comments
 (0)