From a999c1f0a9377e8e7ffddce96e32d68b4f89c632 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Tue, 9 Oct 2018 16:03:14 -0500 Subject: [PATCH] perf(): prevent unnecesary event listener changes --- core/src/components/button/button.tsx | 16 ++++---- core/src/components/checkbox/checkbox.tsx | 16 ++++---- core/src/components/datetime/datetime.tsx | 1 - core/src/components/input/input.tsx | 41 ++++++++++----------- core/src/components/radio/radio.tsx | 20 +++++----- core/src/components/searchbar/searchbar.tsx | 28 +++++++------- core/src/components/select/select.tsx | 12 +++--- core/src/components/textarea/textarea.tsx | 18 ++++----- core/src/components/toggle/toggle.tsx | 16 ++++---- 9 files changed, 82 insertions(+), 86 deletions(-) diff --git a/core/src/components/button/button.tsx b/core/src/components/button/button.tsx index bf364466b6..8cf84845f7 100644 --- a/core/src/components/button/button.tsx +++ b/core/src/components/button/button.tsx @@ -108,20 +108,20 @@ export class Button implements ComponentInterface { } } - private onFocus() { + private onFocus = () => { this.ionFocus.emit(); } - private onKeyUp() { + private onKeyUp = () => { this.keyFocus = true; } - private onBlur() { + private onBlur = () => { this.keyFocus = false; this.ionBlur.emit(); } - private onClick(ev: Event) { + private onClick = (ev: Event) => { if (this.type === 'button') { return openURL(this.win, this.href, ev, this.routerDirection); @@ -177,10 +177,10 @@ export class Button implements ComponentInterface { {...attrs} class="button-native" disabled={this.disabled} - onFocus={this.onFocus.bind(this)} - onKeyUp={this.onKeyUp.bind(this)} - onBlur={this.onBlur.bind(this)} - onClick={this.onClick.bind(this)} + onFocus={this.onFocus} + onKeyUp={this.onKeyUp} + onBlur={this.onBlur} + onClick={this.onClick} > diff --git a/core/src/components/checkbox/checkbox.tsx b/core/src/components/checkbox/checkbox.tsx index fed59e9c02..4df32202a7 100644 --- a/core/src/components/checkbox/checkbox.tsx +++ b/core/src/components/checkbox/checkbox.tsx @@ -99,19 +99,19 @@ export class Checkbox implements ComponentInterface { }); } - private onChange() { + private onChange = () => { this.checked = !this.checked; } - private onKeyUp() { + private onKeyUp = () => { this.keyFocus = true; } - private onFocus() { + private onFocus = () => { this.ionFocus.emit(); } - private onBlur() { + private onBlur = () => { this.keyFocus = false; this.ionBlur.emit(); } @@ -140,10 +140,10 @@ export class Checkbox implements ComponentInterface { type="checkbox" id={this.inputId} aria-labelledby={this.labelId} - onChange={this.onChange.bind(this)} - onFocus={this.onFocus.bind(this)} - onBlur={this.onBlur.bind(this)} - onKeyUp={this.onKeyUp.bind(this)} + onChange={this.onChange} + onFocus={this.onFocus} + onBlur={this.onBlur} + onKeyUp={this.onKeyUp} checked={this.checked} name={this.name} value={this.value} diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index 79898d42f5..899f8c002b 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -527,7 +527,6 @@ export class Datetime implements ComponentInterface { diff --git a/core/src/components/select/select.tsx b/core/src/components/select/select.tsx index e7e00da4c9..c3c16ef458 100644 --- a/core/src/components/select/select.tsx +++ b/core/src/components/select/select.tsx @@ -425,15 +425,15 @@ export class Select implements ComponentInterface { return overlay.dismiss(); } - onKeyUp() { + private onKeyUp = () => { this.keyFocus = true; } - onFocus() { + private onFocus = () => { this.ionFocus.emit(); } - onBlur() { + private onBlur = () => { this.keyFocus = false; this.ionBlur.emit(); } @@ -500,9 +500,9 @@ export class Select implements ComponentInterface { aria-expanded={this.isExpanded ? 'true' : null} aria-disabled={this.disabled ? 'true' : null} onClick={this.open.bind(this)} - onKeyUp={this.onKeyUp.bind(this)} - onFocus={this.onFocus.bind(this)} - onBlur={this.onBlur.bind(this)} + onKeyUp={this.onKeyUp} + onFocus={this.onFocus} + onBlur={this.onBlur} class="select-cover" > diff --git a/core/src/components/textarea/textarea.tsx b/core/src/components/textarea/textarea.tsx index 22a4ac0dbd..4e888465bb 100644 --- a/core/src/components/textarea/textarea.tsx +++ b/core/src/components/textarea/textarea.tsx @@ -186,27 +186,27 @@ export class Textarea implements ComponentInterface { }); } - private onInput(ev: KeyboardEvent) { + private onInput = (ev: Event) => { this.value = this.nativeInput!.value; this.emitStyle(); - this.ionInput.emit(ev); + this.ionInput.emit(ev as KeyboardEvent); } - private onFocus() { + private onFocus = () => { this.hasFocus = true; this.focusChange(); this.ionFocus.emit(); } - private onBlur() { + private onBlur = () => { this.hasFocus = false; this.focusChange(); this.ionBlur.emit(); } - private onKeyDown() { + private onKeyDown = () => { this.checkClearOnEdit(); } @@ -268,10 +268,10 @@ export class Textarea implements ComponentInterface { cols={this.cols} rows={this.rows} wrap={this.wrap} - onInput={this.onInput.bind(this)} - onBlur={this.onBlur.bind(this)} - onFocus={this.onFocus.bind(this)} - onKeyDown={this.onKeyDown.bind(this)} + onInput={this.onInput} + onBlur={this.onBlur} + onFocus={this.onFocus} + onKeyDown={this.onKeyDown} > {this.value} diff --git a/core/src/components/toggle/toggle.tsx b/core/src/components/toggle/toggle.tsx index ee2e4615d7..d17c671f3a 100644 --- a/core/src/components/toggle/toggle.tsx +++ b/core/src/components/toggle/toggle.tsx @@ -154,19 +154,19 @@ export class Toggle implements ComponentInterface { this.nativeInput.focus(); } - private onChange() { + private onChange = () => { this.checked = !this.checked; } - private onKeyUp() { + private onKeyUp = () => { this.keyFocus = true; } - private onFocus() { + private onFocus = () => { this.ionFocus.emit(); } - private onBlur() { + private onBlur = () => { this.keyFocus = false; this.ionBlur.emit(); } @@ -194,10 +194,10 @@ export class Toggle implements ComponentInterface { ,