Code splitting for activities

77 views
Skip to first unread message

Craig Greenhalgh

unread,
Aug 31, 2011, 3:47:43 AM8/31/11
to google-we...@googlegroups.com
Hi,

I have been working on code splitting for my activites. I figured I
could put this in the activity mappers. The following is a snippet of
the getActivity method used to achieve this. I needed to put in a hack
and store the activity in an array as this needed to be final in order
for this to be returned.

What are peoples views and is there a more best practice approach?

Thanks

Craig


final Activity[] activity = new Activity[1];

if (place instanceof LoginPlace)
{
GWT.runAsync(new RunAsyncCallback()
{
public void onFailure(Throwable caught)
{
Window.alert("Code download failed");
}

public void onSuccess()
{
activity[0] = new
LoginActivity(clientFactory.getLoginView(), sessionContext);
}
});

}

return activity[0];

Jens

unread,
Aug 31, 2011, 4:00:35 AM8/31/11
to google-we...@googlegroups.com
Take a look at: http://code.google.com/p/google-web-toolkit/issues/detail?id=5129

Thats what I do to code split activities. Works pretty well.

-- J.

Craig Greenhalgh

unread,
Aug 31, 2011, 4:20:29 AM8/31/11
to google-we...@googlegroups.com
Thanks Jens,

What version of GWT do I need for this and do I need to use GIN ?

I have recently removed GIN in favor of Errai IOC

Thanks

Craig

> --
> 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/-/ptXaReDRzssJ.
> 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.

Thomas Broyer

unread,
Aug 31, 2011, 4:33:18 AM8/31/11
to google-we...@googlegroups.com
So the first time you need your activity, your ActivityMapper actually returns 'null' ? (and loads the activity code in parallel)

Jens

unread,
Aug 31, 2011, 5:04:09 AM8/31/11
to google-we...@googlegroups.com
The used AsyncProvider from GIN will be integrated in GWT 2.4 (see: http://code.google.com/p/google-web-toolkit/source/browse/releases/2.4/user/src/com/google/gwt/core/client/AsyncProvider.java). So if you do not depend on GIN you should wait for GWT 2.4. If you can't wait you can try and rewrite the code to use your DI framework or to use GWT.runAsync directly.

As Thomas said your code example is pretty dangerous. In Dev mode GWT.runAsync acts synchronously so it may work during development. But when you compile your app you will return null the first time you request an activity. Just imagine onSuccess will be executed after getActivity() has finished.

-- J.

Craig Greenhalgh

unread,
Aug 31, 2011, 5:11:20 AM8/31/11
to google-we...@googlegroups.com
Ok thanks guys,

I'll wait for 2.4

Cheers

Craig

> --
> 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/-/xySMboZIpiEJ.

Craig Greenhalgh

unread,
Sep 15, 2011, 11:05:10 AM9/15/11
to google-we...@googlegroups.com
Has anyone got an example of how to use this in 2.4 ?

Thanks again

Craig

Reply all
Reply to author
Forward
0 new messages