Skip to content

Commit

Permalink
Use handleEvent instead arrow function
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Jul 20, 2017
1 parent e61f281 commit ceb3314
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
}

/**
Expand Down Expand Up @@ -64,16 +55,34 @@ 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);
}

/**
* Invoked when the attribute is detached from the DOM.
*/
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;
}
}
}

0 comments on commit ceb3314

Please sign in to comment.