Javascript 框架的自定义事件日志记录

发布于 2024-07-20 04:24:57 字数 679 浏览 8 评论 0原文

想象一下,我有一个 Web 应用程序,其中包含用您最喜欢的 Javascript 库编码的漂亮组件。 我大量使用自定义事件来减少这些组件之间的依赖关系,以便您可以轻松地将它们放置在多个上下文中,在页面上重复它们,和/或按照我认为合适的方式嵌套它们。

这是一幅可爱的图片,但调试可能非常痛苦,因为我还没有找到一种方法来记录我的自定义事件。 理想情况下,我希望能够在我选择的框架中打开日志记录(目前我使用 Prototype),然后获取 DOM 中任意点处触发和观察到的事件的运行日志。

我一直在与其他 F2E 讨论这个问题,并尝试了一些方法:

我如何获得我想要的自定义日志记录?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧伤还要旧人安 2024-07-27 04:24:57

您可能使用一些在 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.

清秋悲枫 2024-07-27 04:24:57

如果您使用 Prototype,我会包装围绕文档的日志记录功能.fire

If you're using Prototype, I would wrap a logging function around document.fire.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文