runAsync + clientBundle = ❤ ?

60 views
Skip to first unread message

JAre JAre

unread,
Sep 20, 2011, 8:43:52 AM9/20/11
to Google Web Toolkit
Hello everyone!
I need to make my resources built into (Data URI) piece of code that
will be called as asynchronous code.

I have a lot of separate asynchronous code and single
clientBundle(that it will use).

Should i initiate resources inside each onSuccess call? Like this:

...
public void onSuccess() {
...
Resources resources = GWT.create(Resources.class);
Image img1 = new Image(resources.img1res());
RootPanel.get("Container").add(img1);
}
...

public void onSuccess() {
...
Resources resources = GWT.create(Resources.class);
Image img2 = new Image(resources.img2res());
RootPanel.get("Container").add(img2);
}
...

Alexandre Dupriez

unread,
Sep 21, 2011, 1:43:23 AM9/21/11
to Google Web Toolkit
Why would you need to create a proxy each time you need to access your
Resources interface?

Just do it one time Resources resources = GWT.create(Resources.class)
and call this instance everywhere (declare it static if needed, since
the instance will not change over the life cycle of your application).

BTW, I do not know if using runAsync for each of your resource is a
good pattern.

Best luck
Alexandre

Thomas Broyer

unread,
Sep 21, 2011, 5:08:39 AM9/21/11
to google-we...@googlegroups.com
When in doubt, pass the -gen argument to the DevMode or Compiler and look at the code that's been generated.

Looking the code (or rather, its javadoc), it seems like everything inside a ClientBundle generated class is 'static':
That means that it makes no difference whether you GWT.create() a new instance each time you need it, or use a singleton. And the compiler will correctly "dispatch" the initialization code of each resource within the appropriate "fragment" created by a runAsync.

In other words, yes: runAsync + clientBundle = ❤ !

JAre JAre

unread,
Sep 21, 2011, 6:48:31 PM9/21/11
to Google Web Toolkit
Thank you for your comprehensive answer.

On Sep 21, 12:08 pm, Thomas Broyer <t.bro...@gmail.com> wrote:
> When in doubt, pass the -gen argument to the DevMode or Compiler and look at
> the code that's been generated.
>
> Looking the code (or rather, its javadoc), it seems like everything inside a
> ClientBundle generated class is 'static':http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/...
Reply all
Reply to author
Forward
0 new messages