Javascript 框架的自定义事件日志记录
想象一下,我有一个 Web 应用程序,其中包含用您最喜欢的 Javascript 库编码的漂亮组件。 我大量使用自定义事件来减少这些组件之间的依赖关系,以便您可以轻松地将它们放置在多个上下文中,在页面上重复它们,和/或按照我认为合适的方式嵌套它们。
这是一幅可爱的图片,但调试可能非常痛苦,因为我还没有找到一种方法来记录我的自定义事件。 理想情况下,我希望能够在我选择的框架中打开日志记录(目前我使用 Prototype),然后获取 DOM 中任意点处触发和观察到的事件的运行日志。
我一直在与其他 F2E 讨论这个问题,并尝试了一些方法:
- 视觉事件< /a> 是一个书签,可以很好地可视化事件绑定的位置,但不提供运行时日志。
- Antenna 就是这样一个日志,但似乎是一个有点 bug,需要修改原型库本身,这感觉就像一个 hack。
我如何获得我想要的自定义日志记录?
Imagine I have a web application with nice components coded up with your favorite Javascript library. I make heavy use of custom events to reduce the dependencies between these components so you can easily place them in multiple contexts, repeat them on the page, and/or nest them as I see fit.
This is a lovely picture, but debugging can be quite a pain, as I haven't found a way to do logging of my custom events. Ideally, I would like to be able to turn on logging in my framework of choice (I use Prototype, currently), and then get a running log of fired and observed events at any point or points in the DOM.
I've been discussing this with other F2E's and a few approaches have been tried:
- Visual Event is a bookmarklet that does a good job of visualizing where events are bound, but doesn't offer a runtime log.
- Antenna Is just such a log, but seems a bit buggy and requires modification of the prototype library itself, which feels like a hack.
How do I go about getting the custom logging I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能使用一些在 Object.prototype 中定义的 X.fireEvent 方法(可能您的固件不熟悉)。
我将研究用您的版本覆盖此方法的方法,该版本将执行日志操作。
You probably using some X.fireEvent method which is (probably-not familiar with your FW) defined in the Object.prototype.
I would investigate the approach to override this one method with your version which will do the log stuff.
如果您使用 Prototype,我会包装围绕
文档的日志记录功能.fire
。If you're using Prototype, I would wrap a logging function around
document.fire
.