GWT - Where should i use code splitting while using places/activities/mappers?

夙愿已清 提交于 2019-12-05 01:14:39

问题


"core" refers to the initial piece of the application that is loaded.

  • In order to bind url to places, GWT uses PlaceTokenizer<P extends Place>. When loading the application from the url, it calls the method P getPlace(String token) to retrieve a new instance of the place to call.

    due to the asynchronous nature of code splitting, I can't create the place inside a runAsync in this method. So I have to put all the places of my app in the core.

  • To link places to activity, GWT callsActivity getActivity(Place place) (from com.google.gwt.activity.shared.ActivityMapper) to retrieve a new instance of the activity.

    Once again, i have to put all my activities in the core.

Here's what I want to try: Write a custom com.google.gwt.place.shared.Delegate that

  • bind itself on PlaceChangeRequestEvent. If the AppPiece corresponding to the requestedPlace isn't loaded, it calls event.setWarning(NEED_TO_LOAD_MODULE)
  • in the confirm(String message) method, always return false when the message equals NEED_TO_LOAD_MODULE (so it doesn't bother the user), and load the module via RunAsync.
  • Once the module is loaded, call goTo(requestedPlace)

Each AppPiece of my application contains a bunch of activies and the corresponding views. Since the mappers are only called when PlaceChangeEventis fired, i could generate a new instance of my activity via AppPiece.getSomeActivityInstance().

I'm pretty sure this will work, but what bother me is that

  • Finding wich AppPiece to load depending on the requestedPlace will force me to write code that will be very similar to my mappers
  • I would like to have my places inside the corresponding AppPiece
  • Overriding Delegate for this purpose is tricky, and I'm looking for a better solution

回答1:


You don't have to put all your activities in the core (as you call it): while an Activity instance is retrieved synchronously, it's allowed to start asynchronously. This is where you'd put your GWT.runAsync call.

See http://code.google.com/p/google-web-toolkit/issues/detail?id=5129 and https://groups.google.com/d/topic/google-web-toolkit/8_P_d4aT-0E/discussion



来源:https://stackoverflow.com/questions/5328599/gwt-where-should-i-use-code-splitting-while-using-places-activities-mappers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!