HandlerManager 如何与源一起工作?
我分析了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 实例的事件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当
source
参数不为null
时,SimpleEventBus
中的doFire
才会更改事件源。HandlerManager
首先使用overrideSource
设置事件源,然后使用隐式null
源调用doFire
,这样它就不会覆盖它。量子ED。
doFire
inSimpleEventBus
only changes the event's source if thesource
argument is notnull
.HandlerManager
first sets the event's source withoverrideSource
and then calldoFire
with an implicitnull
source so it won't overwrite it.QED.