From ceb3314e1004e037afdff1282d88f151a89f538f Mon Sep 17 00:00:00 2001 From: bigopon Date: Thu, 20 Jul 2017 12:24:34 +1000 Subject: [PATCH] Use handleEvent instead arrow function --- src/focus.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/focus.js b/src/focus.js index 2906679..8c264f9 100644 --- a/src/focus.js +++ b/src/focus.js @@ -20,15 +20,6 @@ export class Focus { this.taskQueue = taskQueue; this.isAttached = false; this.needsApply = false; - - this.focusListener = e => { - this.value = true; - }; - this.blurListener = e => { - if (DOM.activeElement !== this.element) { - this.value = false; - } - }; } /** @@ -64,8 +55,8 @@ export class Focus { this.needsApply = false; this._apply(); } - this.element.addEventListener('focus', this.focusListener); - this.element.addEventListener('blur', this.blurListener); + this.element.addEventListener('focus', this); + this.element.addEventListener('blur', this); } /** @@ -73,7 +64,25 @@ export class Focus { */ detached() { this.isAttached = false; - this.element.removeEventListener('focus', this.focusListener); - this.element.removeEventListener('blur', this.blurListener); + this.element.removeEventListener('focus', this); + this.element.removeEventListener('blur', this); + } + + handleEvent(e) { + switch (e.type) { + case 'focus': this.handleFocus(e); break; + case 'blur': this.handleBlur(e); break; + default: break; + } + } + + handleFocus(e) { + this.value = true; + } + + handleBlur(e) { + if (DOM.activeElement !== this.element) { + this.value = false; + } } }