Skip to content

Commit c20bcf9

Browse files
e-cloudmmalerba
authored andcommitted
fix(xxx-intl): replace misused EventEmitter with Subject (#6313)
* fix(xxx-intl): replace misused EventEmitter with Subject According to https://angular.io/api/core/EventEmitter#description, EventEmitter is not for services. And Subject is preferrable. * test(xxx-intl): update the related tests * refactor: remove spaces
1 parent 5ebca5e commit c20bcf9

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

src/lib/datepicker/calendar.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('MdCalendar', () => {
154154
.querySelector('.mat-calendar-period-button');
155155

156156
intl.switchToYearViewLabel = 'Go to year view?';
157-
intl.changes.emit();
157+
intl.changes.next();
158158
fixture.detectChanges();
159159

160160
expect(button.getAttribute('aria-label')).toBe('Go to year view?');

src/lib/datepicker/datepicker-intl.ts

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

9-
import {Injectable, EventEmitter} from '@angular/core';
9+
import {Injectable} from '@angular/core';
10+
import {Subject} from 'rxjs/Subject';
1011

1112

1213
/** Datepicker data that requires internationalization. */
@@ -16,7 +17,7 @@ export class MdDatepickerIntl {
1617
* Stream that emits whenever the labels here are changed. Use this to notify
1718
* components if the labels have changed after initialization.
1819
*/
19-
changes: EventEmitter<void> = new EventEmitter<void>();
20+
changes: Subject<void> = new Subject<void>();
2021

2122
/** A label for the calendar popup (used by screen readers). */
2223
calendarLabel = 'Calendar';

src/lib/datepicker/datepicker.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ describe('MdDatepicker', () => {
571571
const toggle = fixture.debugElement.query(By.css('button')).nativeElement;
572572

573573
intl.openCalendarLabel = 'Open the calendar, perhaps?';
574-
intl.changes.emit();
574+
intl.changes.next();
575575
fixture.detectChanges();
576576

577577
expect(toggle.getAttribute('aria-label')).toBe('Open the calendar, perhaps?');

src/lib/paginator/paginator-intl.ts

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

9-
import {Injectable, EventEmitter} from '@angular/core';
9+
import {Injectable} from '@angular/core';
10+
import {Subject} from 'rxjs/Subject';
1011

1112
/**
1213
* To modify the labels and text displayed, create a new instance of MdPaginatorIntl and
@@ -18,7 +19,7 @@ export class MdPaginatorIntl {
1819
* Stream that emits whenever the labels here are changed. Use this to notify
1920
* components if the labels have changed after initialization.
2021
*/
21-
changes: EventEmitter<void> = new EventEmitter<void>();
22+
changes: Subject<void> = new Subject<void>();
2223

2324
/** A label for the page size selector. */
2425
itemsPerPageLabel = 'Items per page:';

src/lib/paginator/paginator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('MdPaginator', () => {
9696
const label = fixture.nativeElement.querySelector('.mat-paginator-page-size-label');
9797

9898
intl.itemsPerPageLabel = '1337 items per page';
99-
intl.changes.emit();
99+
intl.changes.next();
100100
fixture.detectChanges();
101101

102102
expect(label.textContent).toBe('1337 items per page');

src/lib/sort/sort-header-intl.ts

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

9-
import {Injectable, EventEmitter} from '@angular/core';
9+
import {Injectable} from '@angular/core';
10+
import {Subject} from 'rxjs/Subject';
1011
import {SortDirection} from './sort-direction';
1112

1213
/**
@@ -19,7 +20,7 @@ export class MdSortHeaderIntl {
1920
* Stream that emits whenever the labels here are changed. Use this to notify
2021
* components if the labels have changed after initialization.
2122
*/
22-
changes: EventEmitter<void> = new EventEmitter<void>();
23+
changes: Subject<void> = new Subject<void>();
2324

2425
/** ARIA label for the sorting button. */
2526
sortButtonLabel = (id: string) => {

src/lib/sort/sort.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('MdSort', () => {
148148
const button = header.querySelector('.mat-sort-header-button');
149149

150150
intl.sortButtonLabel = () => 'Sort all of the things';
151-
intl.changes.emit();
151+
intl.changes.next();
152152
fixture.detectChanges();
153153

154154
expect(button.getAttribute('aria-label')).toBe('Sort all of the things');

0 commit comments

Comments
 (0)