Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] unbind 指定的 handler 而不是一下子解绑所有的 #44

Closed
JounQin opened this issue Nov 20, 2018 · 7 comments
Closed

Comments

@JounQin
Copy link
Contributor

JounQin commented Nov 20, 2018

As title.

@jaywcjlove
Copy link
Owner

@JounQin 事实上你可以通过 Scope 来控制。

@JounQin
Copy link
Contributor Author

JounQin commented Nov 20, 2018

@jaywcjlove scope 一次只能生效一个 scope + 'all' 吧?

@jaywcjlove
Copy link
Owner

@JounQin 你可以在代码执行的时候 随意切换 scope

@JounQin
Copy link
Contributor Author

JounQin commented Nov 21, 2018

比如在页面里有很多子模块,他们可能对同一个按键组合同时做监听,子模块卸载的时候要把对应的监听 unbind,切 scope 不能使监听同时生效啊。

@jaywcjlove
Copy link
Owner

@JounQin 你这样,不能把快捷键写到单独的 component 里面去,监听事件绑定到 document 上,如果放到单独的 component 里面,对其它 component 里面的快捷键没有办法控制。

如果不绑定到 document 上,绑定到对应的 component 根节点上,会导致,部分区域获得焦点才能触发事件

解决办法: 根组件, 使用 hotkey.js 通过全局状态 通知 执行事件。

@JounQin
Copy link
Contributor Author

JounQin commented Nov 21, 2018

我只是说明一种情景,每个子模块都可能是不同人维护的,其他组件想监听相同的快捷键,用一个监听全局通知当然是好的,但是为什么不能像 jQuery 对 document 可以监听多次,也可以单独取消某个特定的监听器一样呢?

Related: madrobby/keymaster#133

@jaywcjlove
Copy link
Owner

keymaster 这种方式也可以,我回头给加上去

jaywcjlove added a commit that referenced this issue Nov 21, 2018
@JounQin JounQin closed this as completed Nov 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants