Giter Site home page Giter Site logo

Comments (12)

answershuto avatar answershuto commented on June 9, 2024 1

其实在无论是在 Event 上扩展 还是 navigator 上扩展,都是一个全局的查询能力,只是一个能力归属放在哪个 global 对象下更合适的问题。而对于某些 element 的特定事件,上述 @wssgcg1213 比如 的 InputEvent 能力,属于某个 element 的特定能力,所以如果提供 element 级别的查询,使开发者可以感知某个具体的 element 支持哪些事件。

from chinese-ig.

wssgcg1213 avatar wssgcg1213 commented on June 9, 2024

isEventSupports() 会更好一点吧

from chinese-ig.

zhijs avatar zhijs commented on June 9, 2024

👍

  1. 确实有必要,日常开发中经常会遇到这种探测判断的场景,比如屏幕横竖屏切换事件,如果有相关的检测方法的话,会更方便以及代码的可读性更高。
  2. 可能在 Event 静态方法上扩展会跟合适一些,毕竟 Event 对象基本在所有的环境中都存在。
  3. 上述的 API 方式都不错,我这里也提供一种供参考的方式const isSupports = Event. supports('dbclick');

from chinese-ig.

wssgcg1213 avatar wssgcg1213 commented on June 9, 2024
  • 这个问题确实是存在的,对于事件的特征判断目前缺乏有效路径,尽管有一些事件有 InputEvent 这类 Constructor, 但是像 load 这样的 simple event 是没有构造器的
  • 3 个方案我倾向于 1, 事件支持是由 UserAgent(浏览器) 的实现来决定的, 所以这类判断放在 navigator 下会符合逻辑吧~ 其次 Event 也是不错的, 至于是否要区分 UI Event 和其它 Event 可以再讨论看看

from chinese-ig.

xfq avatar xfq commented on June 9, 2024

看起来挺有用的,在标准层面感觉和HTML/DOM关系比较大,可以考虑在这个issue里先讨论一下这个提案的使用场景和建议语法,初步成型后提到DOM标准?

这是一个DOM的新特性提案的例子,可供参考(不过这个提案比我们讨论的这个要复杂得多):https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md

from chinese-ig.

answershuto avatar answershuto commented on June 9, 2024

考虑到特定元素的一些特有事件,以及 window 上的 onload 事件等,更倾向放在 EventTarget 上提供一个基础能力。继承 EventTarget 的 class 如果有自己的特有事件,可以覆盖该方法提供特有的一些事件判断。

from chinese-ig.

answershuto avatar answershuto commented on June 9, 2024

@xfq 已补充相关提案文档 https://github.com/answershuto/isEventSupports

from chinese-ig.

xfq avatar xfq commented on June 9, 2024

谢谢 @answershuto 。简单看了一下你的提案,有两点建议:

  1. 我觉得需要写一下为什么不能使用 if (window.MouseEvent) 或者 if ("onxxxxx" in window) 这样的用法,因为这可能是常见问题
  2. 例子里写的 isEventSupports(Event event); 和下面的 .isEventSupports('click'); 不匹配,可能需要改为 isEventSupports(DOMString eventType);

from chinese-ig.

answershuto avatar answershuto commented on June 9, 2024

感谢 @xfq 的宝贵建议,相关内容我已经修改以及增加在文档中了。

https://github.com/answershuto/isEventSupports#other-considerations

from chinese-ig.

xfq avatar xfq commented on June 9, 2024

感谢 @answershuto

如果其他同学没有新的comment,我觉得可以在DOM提一个issue了:https://github.com/whatwg/dom/issues

Issue里可以简单介绍一下这个提案,再加一个到 https://github.com/answershuto/isEventSupports 的链接。

from chinese-ig.

xfq avatar xfq commented on June 9, 2024

另外,提案有一个小typo:最后的input will return ture应该是input will return true

from chinese-ig.

answershuto avatar answershuto commented on June 9, 2024

感谢 @xfq ,相关内容已修改。
DOM issue 见 whatwg/dom#968

from chinese-ig.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.