增加.finally()方法

master
宇天 2020-11-06 14:56:11 +08:00
parent 0ea3d62a33
commit 1aebd6d839
3 changed files with 17 additions and 1 deletions

View File

@ -79,6 +79,10 @@ kb.on(['ctrl + c', 'ctrl + v'], ev => {
> 销毁整个键盘监听。
+ .finally(callback`<Function>`)
> 类似Promise.finally, 只要有按键被按下(除了纯辅助功能键外), 都会触发回调.
### 键名对照表
> 键名不区别大小写, 内部统一转为小写。

View File

@ -1,6 +1,6 @@
{
"name": "@bytedo/keyboard",
"version": "1.2.1",
"version": "1.2.2",
"description": "支持各种按钮组合。原生js开发, 无任何依赖(不到2KB)。使用也非常简单。",
"main": "dist/index.js",
"repository": {

View File

@ -49,8 +49,10 @@ function check(ev) {
export default class Keyboard {
constructor(elem) {
this.$elem = elem
hide(this, '__EVENTS__', {})
hide(this, 'paused', false)
hide(this, '__finally__', null)
hide(
this,
@ -112,6 +114,10 @@ export default class Keyboard {
break
}
}
if (this.__finally__) {
this.__finally__(ev)
}
})
)
}
@ -287,4 +293,10 @@ export default class Keyboard {
}
}
}
finally(callback) {
if (typeof callback === 'function') {
this.__finally__ = callback
}
}
}