Skip to content

chore: make all event emitters / subjects readonly #9586

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
Jan 25, 2018
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/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
private _closingActionsSubscription: Subscription;

/** Stream of keyboard events that can close the panel. */
private _closeKeyEventStream = new Subject<void>();
private readonly _closeKeyEventStream = new Subject<void>();

/** View -> model callback called when value changes */
_onChange: (value: any) => void = () => {};
Expand Down Expand Up @@ -209,7 +209,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
}

/** Stream of autocomplete option selections. */
optionSelections: Observable<MatOptionSelectionChange> = defer(() => {
readonly optionSelections: Observable<MatOptionSelectionChange> = defer(() => {
if (this.autocomplete && this.autocomplete.options) {
return merge(...this.autocomplete.options.map(option => option.onSelectionChange));
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterC
@Input() displayWith: ((value: any) => string) | null = null;

/** Event that is emitted whenever an option from the list is selected. */
@Output() optionSelected: EventEmitter<MatAutocompleteSelectedEvent> =
@Output() readonly optionSelected: EventEmitter<MatAutocompleteSelectedEvent> =
new EventEmitter<MatAutocompleteSelectedEvent>();

/**
Expand Down
8 changes: 5 additions & 3 deletions src/lib/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
* Used to facilitate two-way data binding.
* @docs-private
*/
@Output() valueChange = new EventEmitter<any>();
@Output() readonly valueChange = new EventEmitter<any>();

/** Whether the toggle group is selected. */
@Input()
Expand All @@ -142,7 +142,8 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
}

/** Event emitted when the group's value changes. */
@Output() change: EventEmitter<MatButtonToggleChange> = new EventEmitter<MatButtonToggleChange>();
@Output() readonly change: EventEmitter<MatButtonToggleChange> =
new EventEmitter<MatButtonToggleChange>();

constructor(private _changeDetector: ChangeDetectorRef) {
super();
Expand Down Expand Up @@ -357,7 +358,8 @@ export class MatButtonToggle implements OnInit, OnDestroy {
}

/** Event emitted when the group value changes. */
@Output() change: EventEmitter<MatButtonToggleChange> = new EventEmitter<MatButtonToggleChange>();
@Output() readonly change: EventEmitter<MatButtonToggleChange> =
new EventEmitter<MatButtonToggleChange>();

constructor(@Optional() toggleGroup: MatButtonToggleGroup,
@Optional() toggleGroupMultiple: MatButtonToggleGroupMultiple,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
@Input() name: string | null = null;

/** Event emitted when the checkbox's `checked` value changes. */
@Output() change: EventEmitter<MatCheckboxChange> = new EventEmitter<MatCheckboxChange>();
@Output() readonly change: EventEmitter<MatCheckboxChange> =
new EventEmitter<MatCheckboxChange>();

/** Event emitted when the checkbox's `indeterminate` value changes. */
@Output() indeterminateChange: EventEmitter<boolean> = new EventEmitter<boolean>();
@Output() readonly indeterminateChange: EventEmitter<boolean> = new EventEmitter<boolean>();

/** The value attribute of the native input element */
@Input() value: string;
Expand Down
5 changes: 3 additions & 2 deletions src/lib/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,15 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
}

/** Event emitted when the selected chip list value has been changed by the user. */
@Output() change: EventEmitter<MatChipListChange> = new EventEmitter<MatChipListChange>();
@Output() readonly change: EventEmitter<MatChipListChange> =
new EventEmitter<MatChipListChange>();

/**
* Event that emits whenever the raw value of the chip-list changes. This is here primarily
* to facilitate the two-way binding for the `value` input.
* @docs-private
*/
@Output() valueChange: EventEmitter<any> = new EventEmitter<any>();
@Output() readonly valueChange: EventEmitter<any> = new EventEmitter<any>();

/** The chip components contained within this chip list. */
@ContentChildren(MatChip) chips: QueryList<MatChip>;
Expand Down
14 changes: 7 additions & 7 deletions src/lib/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,27 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
}

/** Emits when the chip is focused. */
_onFocus = new Subject<MatChipEvent>();
readonly _onFocus = new Subject<MatChipEvent>();

/** Emits when the chip is blured. */
_onBlur = new Subject<MatChipEvent>();
readonly _onBlur = new Subject<MatChipEvent>();

/** Emitted when the chip is selected or deselected. */
@Output() selectionChange: EventEmitter<MatChipSelectionChange>
= new EventEmitter<MatChipSelectionChange>();
@Output() readonly selectionChange: EventEmitter<MatChipSelectionChange> =
new EventEmitter<MatChipSelectionChange>();

/** Emitted when the chip is destroyed. */
@Output() destroyed = new EventEmitter<MatChipEvent>();
@Output() readonly destroyed = new EventEmitter<MatChipEvent>();

/**
* Emitted when the chip is destroyed.
* @deprecated Use 'destroyed' instead.
* @deletion-target 6.0.0
*/
@Output() destroy: EventEmitter<MatChipEvent> = this.destroyed;
@Output() readonly destroy: EventEmitter<MatChipEvent> = this.destroyed;

/** Emitted when a chip is to be removed. */
@Output() removed: EventEmitter<MatChipEvent> = new EventEmitter<MatChipEvent>();
@Output() readonly removed: EventEmitter<MatChipEvent> = new EventEmitter<MatChipEvent>();

/**
* Emitted when a chip is to be removed.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/common-behaviors/error-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {Subject} from 'rxjs/Subject';
/** @docs-private */
export interface CanUpdateErrorState {
updateErrorState();
stateChanges: Subject<void>;
readonly stateChanges: Subject<void>;
errorState: boolean;
errorStateMatcher: ErrorStateMatcher;
}
Expand All @@ -41,7 +41,7 @@ export function mixinErrorState<T extends Constructor<HasErrorState>>(base: T)
* Stream that emits whenever the state of the input changes such that the wrapping
* `MatFormField needs to run change detection.
*/
stateChanges = new Subject<void>();
readonly stateChanges = new Subject<void>();

errorStateMatcher: ErrorStateMatcher;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/option/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ export class MatOption implements AfterViewChecked {
get disableRipple() { return this._parent && this._parent.disableRipple; }

/** Event emitted when the option is selected or deselected. */
@Output() onSelectionChange = new EventEmitter<MatOptionSelectionChange>();
@Output() readonly onSelectionChange = new EventEmitter<MatOptionSelectionChange>();

/** Emits when the state of the option changes and any parents have to be notified. */
_stateChanges = new Subject<void>();
readonly _stateChanges = new Subject<void>();

constructor(
private _element: ElementRef,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datepicker/calendar-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class MatCalendarBody {
@Input() cellAspectRatio = 1;

/** Emits when a new value is selected. */
@Output() selectedValueChange = new EventEmitter<number>();
@Output() readonly selectedValueChange = new EventEmitter<number>();

_cellClicked(cell: MatCalendarCell): void {
if (!this.allowDisabledSelection && !cell.enabled) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/datepicker/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
@Input() dateFilter: (date: D) => boolean;

/** Emits when the currently selected date changes. */
@Output() selectedChange = new EventEmitter<D>();
@Output() readonly selectedChange = new EventEmitter<D>();

/** Emits when any date is selected. */
@Output() _userSelection = new EventEmitter<void>();
@Output() readonly _userSelection = new EventEmitter<void>();

/** Reference to the current month view component. */
@ViewChild(MatMonthView) monthView: MatMonthView<D>;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/datepicker/datepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ export class MatDatepickerInput<D> implements AfterContentInit, ControlValueAcce
private _disabled: boolean;

/** Emits when a `change` event is fired on this `<input>`. */
@Output() dateChange: EventEmitter<MatDatepickerInputEvent<D>>
= new EventEmitter<MatDatepickerInputEvent<D>>();
@Output() readonly dateChange: EventEmitter<MatDatepickerInputEvent<D>> =
new EventEmitter<MatDatepickerInputEvent<D>>();

/** Emits when an `input` event is fired on this `<input>`. */
@Output() dateInput: EventEmitter<MatDatepickerInputEvent<D>>
= new EventEmitter<MatDatepickerInputEvent<D>>();
@Output() readonly dateInput: EventEmitter<MatDatepickerInputEvent<D>> =
new EventEmitter<MatDatepickerInputEvent<D>>();

/** Emits when the value changes (either due to user input or programmatic change). */
_valueChange = new EventEmitter<D|null>();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datepicker/datepicker-intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MatDatepickerIntl {
* Stream that emits whenever the labels here are changed. Use this to notify
* components if the labels have changed after initialization.
*/
changes: Subject<void> = new Subject<void>();
readonly changes: Subject<void> = new Subject<void>();

/** A label for the calendar popup (used by screen readers). */
calendarLabel = 'Calendar';
Expand Down
4 changes: 2 additions & 2 deletions src/lib/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class MatDatepicker<D> implements OnDestroy {
* @deprecated Switch to the `dateChange` and `dateInput` binding on the input element.
* @deletion-target 6.0.0
*/
@Output() selectedChanged: EventEmitter<D> = new EventEmitter<D>();
@Output() readonly selectedChanged: EventEmitter<D> = new EventEmitter<D>();

/** Classes to be passed to the date picker panel. Supports the same syntax as `ngClass`. */
@Input() panelClass: string | string[];
Expand Down Expand Up @@ -219,7 +219,7 @@ export class MatDatepicker<D> implements OnDestroy {
_datepickerInput: MatDatepickerInput<D>;

/** Emits when the datepicker is disabled. */
_disabledChange = new Subject<boolean>();
readonly _disabledChange = new Subject<boolean>();

constructor(private _dialog: MatDialog,
private _overlay: Overlay,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/datepicker/month-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export class MatMonthView<D> implements AfterContentInit {
@Input() dateFilter: (date: D) => boolean;

/** Emits when a new date is selected. */
@Output() selectedChange = new EventEmitter<D | null>();
@Output() readonly selectedChange = new EventEmitter<D | null>();

/** Emits when any date is selected. */
@Output() _userSelection = new EventEmitter<void>();
@Output() readonly _userSelection = new EventEmitter<void>();

/** The label for this month (e.g. "January 2017"). */
_monthLabel: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datepicker/multi-year-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class MatMultiYearView<D> implements AfterContentInit {
@Input() dateFilter: (date: D) => boolean;

/** Emits when a new month is selected. */
@Output() selectedChange = new EventEmitter<D>();
@Output() readonly selectedChange = new EventEmitter<D>();

/** Grid of calendar cells representing the currently displayed years. */
_years: MatCalendarCell[][];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datepicker/year-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MatYearView<D> implements AfterContentInit {
@Input() dateFilter: (date: D) => boolean;

/** Emits when a new month is selected. */
@Output() selectedChange = new EventEmitter<D>();
@Output() readonly selectedChange = new EventEmitter<D>();

/** Grid of calendar cells representing the months of the year. */
_months: MatCalendarCell[][];
Expand Down
6 changes: 3 additions & 3 deletions src/lib/dialog/dialog-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export class MatDialogRef<T, R = any> {
disableClose: boolean | undefined = this._containerInstance._config.disableClose;

/** Subject for notifying the user that the dialog has finished opening. */
private _afterOpen = new Subject<void>();
private readonly _afterOpen = new Subject<void>();

/** Subject for notifying the user that the dialog has finished closing. */
private _afterClosed = new Subject<R | undefined>();
private readonly _afterClosed = new Subject<R | undefined>();

/** Subject for notifying the user that the dialog has started closing. */
private _beforeClose = new Subject<R | undefined>();
private readonly _beforeClose = new Subject<R | undefined>();

/** Result to be passed to afterClosed. */
private _result: R | undefined;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export const MAT_DIALOG_SCROLL_STRATEGY_PROVIDER = {
@Injectable()
export class MatDialog {
private _openDialogsAtThisLevel: MatDialogRef<any>[] = [];
private _afterAllClosedAtThisLevel = new Subject<void>();
private _afterOpenAtThisLevel = new Subject<MatDialogRef<any>>();
private readonly _afterAllClosedAtThisLevel = new Subject<void>();
private readonly _afterOpenAtThisLevel = new Subject<MatDialogRef<any>>();
private _ariaHiddenElements = new Map<Element, string|null>();

/** Keeps track of the currently-open dialogs. */
Expand All @@ -89,7 +89,7 @@ export class MatDialog {
* Stream that emits when all open dialog have finished closing.
* Will emit on subscribe if there are no open dialogs to begin with.
*/
afterAllClosed: Observable<void> = defer<void>(() => this.openDialogs.length ?
readonly afterAllClosed: Observable<void> = defer<void>(() => this.openDialogs.length ?
this._afterAllClosed :
this._afterAllClosed.pipe(startWith(undefined)));

Expand Down
2 changes: 1 addition & 1 deletion src/lib/expansion/expansion-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class MatExpansionPanel extends _MatExpansionPanelMixinBase
private _hideToggle = false;

/** Stream that emits for changes in `@Input` properties. */
_inputChanges = new Subject<SimpleChanges>();
readonly _inputChanges = new Subject<SimpleChanges>();

/** Optionally defined accordion the expansion panel belongs to. */
accordion: MatAccordion;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/input/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {Subject} from 'rxjs/Subject';
export class MatTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
/** Keep track of the previous textarea value to avoid resizing when the value hasn't changed. */
private _previousValue: string;
private _destroyed = new Subject<void>();
private readonly _destroyed = new Subject<void>();

private _minRows: number;
private _maxRows: number;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
* Stream that emits whenever the state of the input changes such that the wrapping `MatFormField`
* needs to run change detection.
*/
stateChanges = new Subject<void>();
readonly stateChanges = new Subject<void>();

/** A name for this control that can be used by `mat-form-field`. */
controlType = 'mat-input';
Expand Down
4 changes: 2 additions & 2 deletions src/lib/list/selection-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class MatListOption extends _MatListOptionMixinBase
* @deprecated Use the `selectionChange` event on the `<mat-selection-list>` instead.
* @deletion-target 6.0.0
*/
@Output() selectionChange: EventEmitter<MatListOptionChange> =
@Output() readonly selectionChange: EventEmitter<MatListOptionChange> =
new EventEmitter<MatListOptionChange>();

constructor(private _element: ElementRef,
Expand Down Expand Up @@ -301,7 +301,7 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
@ContentChildren(MatListOption) options: QueryList<MatListOption>;

/** Emits a change event whenever the selected state of an option changes. */
@Output() selectionChange: EventEmitter<MatSelectionListChange> =
@Output() readonly selectionChange: EventEmitter<MatSelectionListChange> =
new EventEmitter<MatSelectionListChange>();

/** The currently selected options. */
Expand Down
4 changes: 2 additions & 2 deletions src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export class MatMenu implements AfterContentInit, MatMenuPanel, OnDestroy {
set classList(classes: string) { this.panelClass = classes; }

/** Event emitted when the menu is closed. */
@Output() closed: EventEmitter<void | 'click' | 'keydown'>
= new EventEmitter<void | 'click' | 'keydown'>();
@Output() readonly closed: EventEmitter<void | 'click' | 'keydown'> =
new EventEmitter<void | 'click' | 'keydown'>();

/**
* Event emitted when the menu is closed.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/menu/menu-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class MatMenuItem extends _MatMenuItemMixinBase
private _document: Document;

/** Stream that emits when the menu item is hovered. */
_hovered: Subject<MatMenuItem> = new Subject<MatMenuItem>();
readonly _hovered: Subject<MatMenuItem> = new Subject<MatMenuItem>();

/** Whether the menu item is highlighted. */
_highlighted: boolean = false;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,24 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
@Input('matMenuTriggerFor') menu: MatMenuPanel;

/** Event emitted when the associated menu is opened. */
@Output() menuOpened: EventEmitter<void> = new EventEmitter<void>();
@Output() readonly menuOpened: EventEmitter<void> = new EventEmitter<void>();

/**
* Event emitted when the associated menu is opened.
* @deprecated Switch to `menuOpened` instead
* @deletion-target 6.0.0
*/
@Output() onMenuOpen: EventEmitter<void> = this.menuOpened;
@Output() readonly onMenuOpen: EventEmitter<void> = this.menuOpened;

/** Event emitted when the associated menu is closed. */
@Output() menuClosed: EventEmitter<void> = new EventEmitter<void>();
@Output() readonly menuClosed: EventEmitter<void> = new EventEmitter<void>();

/**
* Event emitted when the associated menu is closed.
* @deprecated Switch to `menuClosed` instead
* @deletion-target 6.0.0
*/
@Output() onMenuClose: EventEmitter<void> = this.menuClosed;
@Output() readonly onMenuClose: EventEmitter<void> = this.menuClosed;

constructor(private _overlay: Overlay,
private _element: ElementRef,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/paginator/paginator-intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class MatPaginatorIntl {
* Stream that emits whenever the labels here are changed. Use this to notify
* components if the labels have changed after initialization.
*/
changes: Subject<void> = new Subject<void>();
readonly changes: Subject<void> = new Subject<void>();

/** A label for the page size selector. */
itemsPerPageLabel: string = 'Items per page:';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class MatPaginator implements OnInit, OnDestroy {
@Input() hidePageSize = false;

/** Event emitted when the paginator changes the page size or page index. */
@Output() page = new EventEmitter<PageEvent>();
@Output() readonly page = new EventEmitter<PageEvent>();

/** Displayed set of page size options. Will be sorted and include current page size. */
_displayedPageSizeOptions: number[];
Expand Down
Loading