HandlerManager 如何与源一起工作?

发布于 2025-01-03 22:20:07 字数 1365 浏览 4 评论 0 原文

我分析了HandlerManager我不看到它如何处理事件源。第 117 行:

public void fireEvent(GwtEvent<?> event) {
    ...
    Object oldSource = event.getSource();
    event.overrideSource(source);
    try {

      // May throw an UmbrellaException.
      eventBus.fireEvent(event); // <--- LOOK HERE
    } catch (com.google.web.bindery.event.shared.UmbrellaException e) {
      throw new UmbrellaException(e.getCauses());
    } finally {
      ....
    }
}

但是简单事件总线实现具有以下代码,第86行:

@Override
public void fireEvent(Event<?> event) {
    doFire(event, null); // <---- SOURCE IS NULL???
}

@Override
public void fireEventFromSource(Event<?> event, Object source) {
    if (source == null) {
      throw new NullPointerException("Cannot fire from a null source");
    }
    doFire(event, source);
}

因此,HandlerManager 不会使用源触发事件,因为它总是调用doFire(event, null);

你能说清楚HandlerManager是如何触发源事件的吗?作为 Widget 中使用的 HandlerManager,它如何仅触发 Widget 实例的事件?

I've analyzed HandlerManager and I do not see how it handles event source. Line 117:

public void fireEvent(GwtEvent<?> event) {
    ...
    Object oldSource = event.getSource();
    event.overrideSource(source);
    try {

      // May throw an UmbrellaException.
      eventBus.fireEvent(event); // <--- LOOK HERE
    } catch (com.google.web.bindery.event.shared.UmbrellaException e) {
      throw new UmbrellaException(e.getCauses());
    } finally {
      ....
    }
}

But simple event bus implementation has following code, line 86:

@Override
public void fireEvent(Event<?> event) {
    doFire(event, null); // <---- SOURCE IS NULL???
}

@Override
public void fireEventFromSource(Event<?> event, Object source) {
    if (source == null) {
      throw new NullPointerException("Cannot fire from a null source");
    }
    doFire(event, source);
}

So, HandlerManager does not fire events with source, because it always calls doFire(event, null);

Could you make it clear how does HandlerManager fire event for source? As HandlerManager used in Widget, how does it fire events for Widget instance only?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

故人爱我别走 2025-01-10 22:20:07

仅当 source 参数不为 null 时,SimpleEventBus 中的 doFire 才会更改事件源。

HandlerManager 首先使用 overrideSource 设置事件源,然后使用隐式 null 源调用 doFire,这样它就不会覆盖它。

量子ED。

doFire in SimpleEventBus only changes the event's source if the source argument is not null.

HandlerManager first sets the event's source with overrideSource and then call doFire with an implicit null source so it won't overwrite it.

QED.

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