import Service from '@ember/service';
import { getOwner } from '@ember/application';
import { get } from '@ember/object';
import { bind, run } from '@ember/runloop';
import { keyDown, keyPress, keyUp } from 'ember-keyboard/listeners/key-events';
import {
  handleKeyEventWithPropagation,
  handleKeyEventWithLaxPriorities
} from 'ember-keyboard/utils/handle-key-event';
import { reverseCompareProp } from 'ember-keyboard/utils/sort';

export default class KeyboardService extends Service {
  isPropagationEnabled = false;

  registeredResponders = new Set();

  get activeResponders() {
    let { registeredResponders } = this;
    return Array.from(registeredResponders).filter(r => r.keyboardActivated);
  }

  get sortedResponders() {
    return this.activeResponders.sort((a, b) => {
      if (this.isPropagationEnabled) {
        return reverseCompareProp(a, b, 'keyboardPriority');
      } else {
        let compareValue = reverseCompareProp(a, b, 'keyboardFirstResponder', Boolean);
        if (compareValue === 0) {
          return reverseCompareProp(a, b, 'keyboardPriority');
        }
        return compareValue;
      }
    });
  }

  get firstResponders() {
    return this.sortedResponders.filter(r => r.keyboardFirstResponder);
  }

  get normalResponders() {
    return this.sortedResponders.filter(r => !r.keyboardFirstResponder);
  }

  constructor(...args) {
    super(...args);

    if (typeof FastBoot !== 'undefined') {
      return;
    }

    const config = getOwner(this).resolveRegistration('config:environment') || {};

    const isPropagationEnabled = Boolean(get(config, 'emberKeyboard.propagation'));
    this.isPropagationEnabled = isPropagationEnabled;

    this._boundRespond = bind(this, this._respond);
    this._listeners = get(config, 'emberKeyboard.listeners') || ['keyUp', 'keyDown', 'keyPress'];
    this._listeners = this._listeners.map((listener) => listener.toLowerCase());

    this._listeners.forEach((type) => {
      document.addEventListener(type, this._boundRespond);
    });
  }

  willDestroy(...args) {
    super.willDestroy(...args);

    if (typeof FastBoot !== 'undefined') {
      return;
    }

    this._listeners.forEach((type) => {
      document.removeEventListener(type, this._boundRespond);
    });
  }

  _respond(event) {
    run(() => {
      if (this.isPropagationEnabled) {
        let { firstResponders, normalResponders } = this;
        handleKeyEventWithPropagation(event, { firstResponders, normalResponders });
      } else {
        let { sortedResponders } = this;
        handleKeyEventWithLaxPriorities(event, sortedResponders);
      }
    });
  }

  register(responder) {
    this.registeredResponders.add(responder);
  }

  unregister(responder) {
    this.registeredResponders.delete(responder);
  }

  keyDown(...args) {
    return keyDown(...args);
  }

  keyPress(...args) {
    return keyPress(...args);
  }

  keyUp(...args) {
    return keyUp(...args);
  }
}

@@ -82,24 +82,32 @@
 n';%0Aimport %7B
+ action,
  get %7D from 
@@ -135,14 +135,8 @@
 rt %7B
- bind,
  run
@@ -1688,60 +1688,8 @@
 d;%0A%0A
-    this._boundRespond = bind(this, this._respond);%0A
     
@@ -1782,16 +1782,16 @@
 ress'%5D;%0A
+
     this
@@ -1940,38 +1940,33 @@
 ner(type, this._
-boundR
+r
 espond);%0A    %7D);
@@ -2184,14 +2184,9 @@
 is._
-boundR
+r
 espo
@@ -2203,16 +2203,26 @@
 );%0A  %7D%0A%0A
+  @action%0A
   _respo

Simplify event listener in service using @action decorator