Skip to content

Commit

Permalink
fix(xxx-intl): replace misused EventEmitter with Subject (#6313)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
e-cloud authored and mmalerba committed Aug 8, 2017
1 parent 5ebca5e commit c20bcf9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/datepicker/calendar.spec.ts
Expand Up @@ -154,7 +154,7 @@ describe('MdCalendar', () => {
.querySelector('.mat-calendar-period-button');

intl.switchToYearViewLabel = 'Go to year view?';
intl.changes.emit();
intl.changes.next();
fixture.detectChanges();

expect(button.getAttribute('aria-label')).toBe('Go to year view?');
Expand Down
5 changes: 3 additions & 2 deletions src/lib/datepicker/datepicker-intl.ts
Expand Up @@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, EventEmitter} from '@angular/core';
import {Injectable} from '@angular/core';
import {Subject} from 'rxjs/Subject';


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

/** A label for the calendar popup (used by screen readers). */
calendarLabel = 'Calendar';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datepicker/datepicker.spec.ts
Expand Up @@ -571,7 +571,7 @@ describe('MdDatepicker', () => {
const toggle = fixture.debugElement.query(By.css('button')).nativeElement;

intl.openCalendarLabel = 'Open the calendar, perhaps?';
intl.changes.emit();
intl.changes.next();
fixture.detectChanges();

expect(toggle.getAttribute('aria-label')).toBe('Open the calendar, perhaps?');
Expand Down
5 changes: 3 additions & 2 deletions src/lib/paginator/paginator-intl.ts
Expand Up @@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, EventEmitter} from '@angular/core';
import {Injectable} from '@angular/core';
import {Subject} from 'rxjs/Subject';

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

/** A label for the page size selector. */
itemsPerPageLabel = 'Items per page:';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/paginator/paginator.spec.ts
Expand Up @@ -96,7 +96,7 @@ describe('MdPaginator', () => {
const label = fixture.nativeElement.querySelector('.mat-paginator-page-size-label');

intl.itemsPerPageLabel = '1337 items per page';
intl.changes.emit();
intl.changes.next();
fixture.detectChanges();

expect(label.textContent).toBe('1337 items per page');
Expand Down
5 changes: 3 additions & 2 deletions src/lib/sort/sort-header-intl.ts
Expand Up @@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

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

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

/** ARIA label for the sorting button. */
sortButtonLabel = (id: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sort/sort.spec.ts
Expand Up @@ -148,7 +148,7 @@ describe('MdSort', () => {
const button = header.querySelector('.mat-sort-header-button');

intl.sortButtonLabel = () => 'Sort all of the things';
intl.changes.emit();
intl.changes.next();
fixture.detectChanges();

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

0 comments on commit c20bcf9

Please sign in to comment.