MVC and Code Splitting

34 views
Skip to first unread message

Xybrek

unread,
Jan 14, 2012, 2:12:44 PM1/14/12
to Google-We...@googlegroups.com
In my application there are many views and controllers, however not all
are needed at once, mostly the view that is loaded depends on the URL
fragment(s).

In what way or pattern a Controller and View be wrapped in a
GWT.runAsync so that only controllers and views needed are loaded?

I just need to get some ideas on how I will implement this.

In my case, I have a home-grown MVC. My application parse the Url
fragment and then show() the appropriate view. In which the parameter of
the show() function is a key String that will then be used to get the
views that are stored in a HashMap.

Everything, the Controllers, Models and Views are instantiated during
onModuleLoad()

Any ideas?

Thomas Broyer

unread,
Jan 14, 2012, 3:12:36 PM1/14/12
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Start by "lazy instantiating" your components, then throwing runAsync in will become much easier.

If you have interfaces, you could try AsyncProxy instead; but if you want lazy-loading, start by architecturing your app around that pattern.

Before:
// in onModuleLoad
map.put("foo", createFoo());
map.put("bar", createBar());
// then retrieving the objects:
return map.get(key);

After:
//when retrieving the objects
Object o = map.get(key);
if (o == null) {
  if ("foo".equals(key)) {
    o = createFoo();
  } else if ("bar".equals(key)) {
    o = createBar();
  }
  map.put(key, o);
}
return o;

Adding runAsync would mean changing the getViewFromToken from synchronous to asynchronous, with a RunAsyncCallback as an additional argument.

Xybrek

unread,
Jan 15, 2012, 6:28:38 AM1/15/12
to Google-We...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/aSVUUp_8tRMJ.
> To post to this group, send email to
> google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.


That's a nice pattern. I did applied this approach and works. However,
my problem is not solved yet, because the GWT-Recaptcha is still causing
request to a external site even if I have used that approach.

I am yet to understand how to fix this thing.

Reply all
Reply to author
Forward
0 new messages