On Saturday, January 14, 2012 8:12:44 PM UTC+1, Xybrek wrote: > > 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? >
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. -- 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-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.