GWT - Where should i use code splitting while usin

2019-03-31 02:30发布

"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条回答
一夜七次
2楼-- · 2019-03-31 02:46

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

查看更多
登录 后发表回答