GWT. Where should I use code splitting when using places / actions / cartographers?

"core" refers to the source part of the downloaded application.

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

    due to the asynchronous nature of the code splitting, I cannot create a space inside runAsync in this method. Therefore, I have to put all the places in my application into the kernel.

  • To associate places with activity, GWT calls Activity getActivity(Place place) (from com.google.gwt.activity.shared.ActivityMapper ) to get a new instance of the activity.

    Once again, I have to put all my actions in the kernel.

Here is what I want to try: write a custom com.google.gwt.place.shared.Delegate which

  • bind yourself to a PlaceChangeRequestEvent . If the AppPiece corresponding to the requested item is not loaded, it calls event.setWarning(NEED_TO_LOAD_MODULE)
  • in the confirm(String message) method always returns false when the message is NEED_TO_LOAD_MODULE (therefore, it does not bother the user) and loads the module through runAsync .
  • After loading the module, call goTo(requestedPlace)

Each AppPiece of my application contains a bunch of actions and corresponding views. Since mappers is only called when PlaceChangeEvent starts, I could create a new instance of my action through AppPiece.getSomeActivityInstance() .

I'm sure it will work, but it bothers me that

  • Finding what AppPiece to load depending on the requested parameter will make me write code that will be very similar to my cartographers
  • I would like to have my places inside the corresponding AppPiece
  • Overriding Delegate for this purpose is difficult, and I'm looking for a better solution.
+4
source share
1 answer

You do not need to add all your actions to the kernel (as you call it): while an Activity instance is retrieved synchronously, it allows you to start asynchronously. Here you put your call to GWT.runAsync .

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

+5
source

Source: https://habr.com/ru/post/1343960/


All Articles