[英]Which GWT EventBus should I use?
在gwt-user.jar中有2個EventBus接口和SimpleEventBus implmentations。
com.google.gwt.event.shared.EventBus
和com.google.web.bindery.event.shared.EventBus
我將這些稱為'gwt.event'和'web.bindery'。
查看JavaDocs和源代碼,我可以看到gwt.event只包含web.bindery。 但是,gwt.event實現還隱藏了許多已棄用的方法
那么我應該使用哪種實現方式? (我在GWT 2.4上)
通常,您應該使用com.google.web.bindery
那個。 以前唯一的版本是com.google.gwt.event
,但是當RequestFactory和AutoBeans從GWT本身移出並進入com.google.web.bindery
,它們可以在非GWT客戶端中工作。
如果您在演示者中使用com.google.web.bindery
版本,則可以在需要時更輕松地使用外部GWT應用。 將該實例傳遞給PlaceController
和其他使用EventBus的類時,您也不會收到棄用警告。
我知道這個問題已經有了答案,但在添加以下內容時可能值得。 正如我在上面的評論中所說,Activity仍然需要com.google.gwt.event.shared.EventBus類。 為了避免棄用警告,我做了以下(我使用GIN):
public class GinClientModule extends AbstractGinModule {
@Override
protected void configure() {
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
...
}
@Provides
@Singleton
public com.google.gwt.event.shared.EventBus adjustEventBus(
EventBus busBindery) {
return (com.google.gwt.event.shared.EventBus) busBindery;
}
...
通過這樣做,您將始終使用bindery包中“新”版本的Event總線中的對象。
如果您使用活動,那么您可能必須使用已棄用的活動,至少在他們清理整個API之前: http : //code.google.com/p/google-web-toolkit/issues/detail?id = 6653 。
使選擇更加復雜。 我在我的GWT應用程序中使用guava,谷歌人已經在那里添加了另一個EventBus(甚至更少的功能完成)。
也許這些人需要坐在一起定義一個實現來統治它們?
顯然我想避免對GWT代碼中沒有嚴格使用的代碼的GWT的所有依賴,所以Guava對我來說很有趣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.