Skip to content

Commit

Permalink
Void returns where type doesn't matter
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Mar 30, 2020
1 parent a9fb9c1 commit d8ed7cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"size-limit": [
{
"path": "./dist/index.js",
"limit": "1 kB"
"limit": "700 B"
}
],
"husky": {
Expand Down
13 changes: 3 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export const KEY_MAP: { [code: string]: string } = {
down: "arrowdown"
};

/**
* Valid modifier keys.
*/
export const MODIFIERS = ["shift", "control", "alt", "meta"];

/**
* Continue propagating the event to older listeners.
*/
Expand All @@ -35,13 +30,12 @@ export const SHOULD_PROPAGATE = true;
* Stringify a keyboard event.
*/
export function keyboardEventCombo(e: KeyboardEvent) {
const keys = new Set<string>();
const keys = new Set<string>([e.key.toLocaleLowerCase()]);

if (e.shiftKey) keys.add("shift");
if (e.ctrlKey) keys.add("control");
if (e.altKey) keys.add("alt");
if (e.metaKey) keys.add("meta");
if (MODIFIERS.indexOf(e.key) === -1) keys.add(e.key.toLowerCase());

return Array.from(keys)
.sort()
Expand Down Expand Up @@ -113,20 +107,19 @@ export class Keyboard {
listeners: KeyHandler[] = [];

addListener(callback: KeyHandler) {
return this.listeners.push(callback);
this.listeners.push(callback);
}

removeListener(callback: KeyHandler) {
const indexOf = this.listeners.indexOf(callback);
if (indexOf > -1) this.listeners.splice(indexOf, 1);
return indexOf;
}

getHandler() {
const listener = this.getListener();

return (event: KeyboardEvent) => {
return listener(event, keyboardEventCombo(event));
listener(event, keyboardEventCombo(event));
};
}

Expand Down

0 comments on commit d8ed7cd

Please sign in to comment.