问题
"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 methodP 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 calls
Activity getActivity(Place place)
(fromcom.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 callsevent.setWarning(NEED_TO_LOAD_MODULE)
- in the
confirm(String message)
method, always return false when the message equalsNEED_TO_LOAD_MODULE
(so it doesn't bother the user), and load the module viaRunAsync
. - 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 PlaceChangeEvent
is 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