add attrMix.js

This commit is contained in:
zhw2590582 committed 2022-01-07 18:35:05 +08:00
1 parent 1438ce5e82
commit 938e8718bc
12 files changed
+268 -232

No files matched your search

+9 -4
View File
@@ -1,5 +1,3 @@
import { errorHandle } from './utils';
export default class Hotkey {
constructor(art) {
this.keys = {};
@@ -56,8 +54,6 @@ export default class Hotkey {
}
add(key, event) {
errorHandle(typeof key === 'number', 'The Hotkey.add() first parameter is not a number');
errorHandle(typeof event === 'function', 'The Hotkey.add() second parameter is not a function');
if (this.keys[key]) {
this.keys[key].push(event);
} else {
@@ -65,4 +61,13 @@ export default class Hotkey {
}
return this;
}
remove(key, event) {
if (this.keys[key]) {
const index = this.keys[key].indexOf(event);
if (index !== -1) {
this.keys[key].splice(index, 1);
}
}
}
}