I have an application with 3 keyboard shortcuts. They only get fired if the focus is within a row on a grid, so I have added a listener to handle this:
if (grid) {
var host = grid.hostElement;
//handle the keydown event
host.addEventListener('keydown', function (e) {
if (e.altKey && e.key == "q") {
doSomething(grid);
}
if (e.altKey && e.key == "n") {
doSomethingElse(grid);
}
if (e.altKey && e.key == "u") {
doAThirdThing(grid);
}
});
}
This is working fine, but is this the most efficient way to handle this, from a performance standpoint? Should I be using a switch or multiple listeners instead?