Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 28fed21

Browse files
authored
chore: Remove EventRegistry usage (#1228)
1 parent f8a3eb6 commit 28fed21

File tree

17 files changed

+101
-220
lines changed

17 files changed

+101
-220
lines changed

packages/button/button.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
OnDestroy,
1111
ViewEncapsulation
1212
} from '@angular/core';
13-
import { EventRegistry, toBoolean } from '@angular-mdc/web/common';
13+
import { toBoolean } from '@angular-mdc/web/common';
1414
import { MdcRipple } from '@angular-mdc/web/ripple';
1515
import { MdcIcon } from '@angular-mdc/web/icon';
1616

@@ -19,18 +19,15 @@ import { MdcIcon } from '@angular-mdc/web/icon';
1919
exportAs: 'mdcButton',
2020
selector: 'button[mdc-button], a[mdc-button]',
2121
template: '<ng-content></ng-content>',
22-
providers: [
23-
MdcRipple,
24-
EventRegistry
25-
],
22+
providers: [MdcRipple],
2623
encapsulation: ViewEncapsulation.None,
2724
changeDetection: ChangeDetectionStrategy.OnPush
2825
})
2926
export class MdcButton implements AfterContentInit, OnDestroy {
3027
@Input()
3128
get raised(): boolean { return this._raised; }
3229
set raised(value: boolean) {
33-
this.setRaised(value);
30+
this._raised = toBoolean(value);
3431
}
3532
protected _raised: boolean = false;
3633

@@ -44,7 +41,7 @@ export class MdcButton implements AfterContentInit, OnDestroy {
4441
@Input()
4542
get dense(): boolean { return this._dense; }
4643
set dense(value: boolean) {
47-
this.setDense(value);
44+
this._dense = toBoolean(value);
4845
}
4946
protected _dense: boolean = false;
5047

@@ -58,14 +55,14 @@ export class MdcButton implements AfterContentInit, OnDestroy {
5855
@Input()
5956
get unelevated(): boolean { return this._unelevated; }
6057
set unelevated(value: boolean) {
61-
this.setUnelevated(value);
58+
this._unelevated = toBoolean(value);
6259
}
6360
protected _unelevated: boolean = false;
6461

6562
@Input()
6663
get outlined(): boolean { return this._outlined; }
6764
set outlined(value: boolean) {
68-
this.setOutlined(value);
65+
this._outlined = toBoolean(value);
6966
}
7067
protected _outlined: boolean = false;
7168

@@ -134,14 +131,6 @@ export class MdcButton implements AfterContentInit, OnDestroy {
134131
}
135132
}
136133

137-
setRaised(raised: boolean): void {
138-
this._raised = toBoolean(raised);
139-
}
140-
141-
setDense(dense: boolean): void {
142-
this._dense = toBoolean(dense);
143-
}
144-
145134
setPrimary(primary: boolean): void {
146135
this._primary = toBoolean(primary);
147136

@@ -158,14 +147,6 @@ export class MdcButton implements AfterContentInit, OnDestroy {
158147
}
159148
}
160149

161-
setUnelevated(unelevated: boolean): void {
162-
this._unelevated = toBoolean(unelevated);
163-
}
164-
165-
setOutlined(outlined: boolean): void {
166-
this._outlined = toBoolean(outlined);
167-
}
168-
169150
setIcon(icon: any): void {
170151
this._icon = icon;
171152

packages/card/card.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export class MdcCardMedia {
3131
@Input()
3232
get square(): boolean { return this._square; }
3333
set square(value: boolean) {
34-
this.setSquare(value);
34+
this._square = toBoolean(value);
3535
}
3636
private _square: boolean;
3737

3838
@Input()
3939
get wide(): boolean { return this._wide; }
4040
set wide(value: boolean) {
41-
this.setWide(value);
41+
this._wide = toBoolean(value);
4242
}
4343
private _wide: boolean;
4444

@@ -51,14 +51,6 @@ export class MdcCardMedia {
5151
}
5252

5353
constructor(public elementRef: ElementRef) { }
54-
55-
setWide(wide: boolean): void {
56-
this._wide = toBoolean(wide);
57-
}
58-
59-
setSquare(square: boolean): void {
60-
this._square = toBoolean(square);
61-
}
6254
}
6355

6456
@Directive({
@@ -175,7 +167,7 @@ export class MdcCard {
175167
@Input()
176168
get outlined(): boolean { return this._outlined; }
177169
set outlined(value: boolean) {
178-
this.setOutlined(value);
170+
this._outlined = toBoolean(value);
179171
}
180172
private _outlined: boolean;
181173

@@ -185,8 +177,4 @@ export class MdcCard {
185177
}
186178

187179
constructor(public elementRef: ElementRef) { }
188-
189-
setOutlined(outlined: boolean): void {
190-
this._outlined = toBoolean(outlined);
191-
}
192180
}

packages/checkbox/checkbox.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
ViewEncapsulation
1515
} from '@angular/core';
1616
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
17-
import { isBrowser, EventRegistry, toBoolean } from '@angular-mdc/web/common';
17+
import { isBrowser, toBoolean } from '@angular-mdc/web/common';
1818
import { MdcRipple } from '@angular-mdc/web/ripple';
1919
import { MdcFormFieldControl } from '@angular-mdc/web/form-field';
2020

@@ -81,7 +81,6 @@ export const MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
8181
providers: [
8282
MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR,
8383
MdcRipple,
84-
EventRegistry,
8584
[{ provide: MdcFormFieldControl, useExisting: MdcCheckbox }]
8685
],
8786
encapsulation: ViewEncapsulation.None,
@@ -97,16 +96,16 @@ export class MdcCheckbox implements AfterViewInit, ControlValueAccessor, OnDestr
9796
removeNativeControlAttr: (attr: string) => this._getInputElement().removeAttribute(attr),
9897
registerAnimationEndHandler: (handler: EventListener) => {
9998
if (isBrowser()) {
100-
this._registry.listen(getCorrectEventName(window, 'animationend'), handler, this._getHostElement());
99+
this._getHostElement().addEventListener(getCorrectEventName(window, 'animationend'), handler);
101100
}
102101
},
103102
deregisterAnimationEndHandler: (handler: EventListener) => {
104103
if (isBrowser()) {
105-
this._registry.unlisten(getCorrectEventName(window, 'animationend'), handler);
104+
this._getHostElement().removeEventListener(getCorrectEventName(window, 'animationend'), handler);
106105
}
107106
},
108-
registerChangeHandler: (handler: EventListener) => this._registry.listen('change', handler, this._getInputElement()),
109-
deregisterChangeHandler: (handler: EventListener) => this._registry.unlisten('change', handler),
107+
registerChangeHandler: (handler: EventListener) => this._getHostElement().addEventListener('change', handler),
108+
deregisterChangeHandler: (handler: EventListener) => this._getHostElement().removeEventListener('change', handler),
110109
getNativeControl: () => this._getInputElement(),
111110
forceLayout: () => this._getHostElement().offsetWidth,
112111
isAttachedToDOM: () => !!this.inputEl
@@ -191,8 +190,7 @@ export class MdcCheckbox implements AfterViewInit, ControlValueAccessor, OnDestr
191190
constructor(
192191
private _changeDetectorRef: ChangeDetectorRef,
193192
public elementRef: ElementRef,
194-
public ripple: MdcRipple,
195-
private _registry: EventRegistry) { }
193+
public ripple: MdcRipple) { }
196194

197195
ngAfterViewInit(): void {
198196
this._foundation.init();
@@ -245,11 +243,11 @@ export class MdcCheckbox implements AfterViewInit, ControlValueAccessor, OnDestr
245243
}
246244

247245
/**
248-
* Event handler for checkbox input element.
249-
* Toggles checked state if element is not disabled.
250-
* Do not toggle on (change) event since IE doesn't fire change event when
251-
* indeterminate checkbox is clicked.
252-
*/
246+
* Event handler for checkbox input element.
247+
* Toggles checked state if element is not disabled.
248+
* Do not toggle on (change) event since IE doesn't fire change event when
249+
* indeterminate checkbox is clicked.
250+
*/
253251
_onInputClick(evt: Event) {
254252
evt.stopPropagation();
255253

@@ -262,12 +260,10 @@ export class MdcCheckbox implements AfterViewInit, ControlValueAccessor, OnDestr
262260
setIndeterminate(indeterminate: boolean): void {
263261
if (this.disabled) { return; }
264262

265-
const previousValue = this.indeterminate;
266-
267263
this._indeterminate = toBoolean(indeterminate);
268-
this._foundation.setIndeterminate(indeterminate);
269-
this.indeterminateChange.emit({ source: this, indeterminate: indeterminate });
270-
if (!indeterminate && !this.indeterminateToChecked) {
264+
this._foundation.setIndeterminate(this.indeterminate);
265+
this.indeterminateChange.emit({ source: this, indeterminate: this.indeterminate });
266+
if (!this.indeterminate && !this.indeterminateToChecked) {
271267
this._checked = false;
272268
}
273269

packages/common/event-registry.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/common/public-api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './boolean-property';
2-
export * from './event-registry';
32
export * from './keycodes';
43
export * from './number-property';
54
export * from './option';

packages/drawer/drawer.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ViewChild,
1313
ViewEncapsulation
1414
} from '@angular/core';
15-
import { isBrowser, EventRegistry, toBoolean } from '@angular-mdc/web/common';
15+
import { isBrowser, toBoolean } from '@angular-mdc/web/common';
1616

1717
import { MdcDrawerNavigation } from './drawer.directives';
1818
import { MDCDrawerAdapter } from './adapter';
@@ -33,7 +33,6 @@ export type MdcDrawerType = 'persistent' | 'permanent' | 'temporary';
3333
<ng-content></ng-content>
3434
</mdc-drawer-navigation>
3535
`,
36-
providers: [EventRegistry],
3736
changeDetection: ChangeDetectionStrategy.OnPush,
3837
encapsulation: ViewEncapsulation.None
3938
})
@@ -94,26 +93,29 @@ export class MdcDrawer implements OnDestroy {
9493
eventTargetHasClass: (target: HTMLElement, className: string) => target.classList.contains(className),
9594
hasNecessaryDom: () => !!this.drawerNav,
9695
registerInteractionHandler: (evt: string, handler: EventListener) =>
97-
this._registry.listen(util.remapEvent(evt), handler, this._getHostElement(), util.applyPassive()),
98-
deregisterInteractionHandler: (evt: string, handler: EventListener) => this._registry.unlisten(evt, handler),
96+
this._getHostElement().addEventListener(util.remapEvent(evt), handler, util.applyPassive()),
97+
deregisterInteractionHandler: (evt: string, handler: EventListener) =>
98+
this._getHostElement().removeEventListener(evt, handler, util.applyPassive()),
9999
registerDrawerInteractionHandler: (evt: string, handler: EventListener) => {
100100
if (this.drawerElement) {
101-
this._registry.listen(util.remapEvent(evt), handler, this.drawerElement.nativeElement);
101+
this.drawerElement.nativeElement.addEventListener(util.remapEvent(evt), handler);
102102
}
103103
},
104-
deregisterDrawerInteractionHandler: (evt: string, handler: EventListener) => this._registry.unlisten(evt, handler),
104+
deregisterDrawerInteractionHandler: (evt: string, handler: EventListener) =>
105+
this.drawerElement.nativeElement.removeEventListener(evt, handler),
105106
registerTransitionEndHandler: (handler: EventListener) => {
106107
if (this.drawerElement) {
107-
this._registry.listen('transitionend', handler, this.drawerElement.nativeElement);
108+
this.drawerElement.nativeElement.addEventListener('transitionend', handler);
108109
}
109110
},
110-
deregisterTransitionEndHandler: (handler: EventListener) => this._registry.unlisten('transitionend', handler),
111+
deregisterTransitionEndHandler: (handler: EventListener) =>
112+
this.drawerElement.nativeElement.removeEventListener('transitionend', handler),
111113
registerDocumentKeydownHandler: (handler: EventListener) => {
112114
if (isBrowser()) {
113-
this._registry.listen('keydown', handler, document);
115+
document.addEventListener('keydown', handler);
114116
}
115117
},
116-
deregisterDocumentKeydownHandler: (handler: EventListener) => this._registry.unlisten('keydown', handler),
118+
deregisterDocumentKeydownHandler: (handler: EventListener) => document.removeEventListener('keydown', handler),
117119
getDrawerWidth: () => this._getHostElement().offsetWidth,
118120
setTranslateX: (value) => {
119121
if (this.drawerNav) {
@@ -150,8 +152,7 @@ export class MdcDrawer implements OnDestroy {
150152
constructor(
151153
private _changeDetectorRef: ChangeDetectorRef,
152154
public renderer: Renderer2,
153-
public elementRef: ElementRef,
154-
private _registry: EventRegistry) {
155+
public elementRef: ElementRef) {
155156

156157
this._initializeFoundation(this._drawer);
157158
}
@@ -168,13 +169,13 @@ export class MdcDrawer implements OnDestroy {
168169
this._initializeFoundation(drawer);
169170

170171
if (drawer === 'temporary') {
171-
this._registry.listen('click', () => {
172+
this.drawerElement.nativeElement.addEventListener('click', () => {
172173
if (this.closeOnClick) {
173174
this._foundation.close();
174175
}
175-
}, this.drawerElement.nativeElement);
176+
});
176177
} else if (drawer === 'temporary') {
177-
this._registry.unlisten('click', () => {
178+
this.drawerElement.nativeElement.removeEventListener('click', () => {
178179
if (this.closeOnClick) {
179180
this._foundation.close();
180181
}
@@ -255,11 +256,11 @@ export class MdcDrawer implements OnDestroy {
255256
}
256257
}
257258

258-
getDrawerWidth(): any {
259+
getDrawerWidth(): number {
259260
return this._foundation ? this._mdcAdapter.getDrawerWidth() : this._getHostElement().offsetWidth;
260261
}
261262

262-
private _getHostElement() {
263+
private _getHostElement(): HTMLElement {
263264
return this.elementRef.nativeElement;
264265
}
265266
}

0 commit comments

Comments
 (0)