github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/helpers/keyboard-commands.js (about)

     1  import Helper from '@ember/component/helper';
     2  import { inject as service } from '@ember/service';
     3  
     4  /**
     5    `{{keyboard-commands}}` helper used to initialize and tear down contextual keynav commands
     6    @public
     7    @method keyboard-commands
     8   */
     9  export default class keyboardCommands extends Helper {
    10    @service keyboard;
    11  
    12    constructor() {
    13      super(...arguments);
    14    }
    15  
    16    compute([commands]) {
    17      if (commands) {
    18        this.commands = commands;
    19        this.keyboard.addCommands(commands);
    20      }
    21    }
    22    willDestroy() {
    23      super.willDestroy();
    24      this.keyboard.removeCommands(this.commands);
    25    }
    26  }