Right way to load gwt-maps library in GWTP app

66 views
Skip to first unread message

Arpit Tripathi

unread,
Oct 2, 2014, 6:18:37 AM10/2/14
to gwt-pl...@googlegroups.com
I'm trying to use https://github.com/branflake2267/GWT-Maps-V3-Api with GWTP. 
It's required to load a bunch of libraries before APIs can be used. What's the best way to achieve this?

As of now, I'm loading everything in Bootstrapper but if someone invokes a function before load completes, code will break.

Thanks,
Arpit

Richard Wallis

unread,
Oct 2, 2014, 6:28:25 AM10/2/14
to gwt-pl...@googlegroups.com
You either need to wrap all calls to the maps api in some kind of callback to see if it's loaded, or wait for it to load before invoking your placemanager.

In the second if your code used to be 

public void onBootstrap() {
    placeManager.revealCurrentPlace();
}

It would become:

public void onBootstrap() {
 Runnable onLoad = new Runnable() {
      @Override
      public void run() {
        placeManager.revealCurrentPlace();
      }
    };

    LoadApi.go(onLoad, loadLibraries, sensor);
}

which should ensure that no code runs before the api is loaded.

--
You received this message because you are subscribed to the Google Groups "GWTP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gwt-platform...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arpit Tripathi

unread,
Oct 2, 2014, 12:23:57 PM10/2/14
to gwt-pl...@googlegroups.com
Thanks.
Is, loading all libraries on bootstrap, a recommended approach? How should I take advantage of Code Splitting if I'm using maps library for few specific cases only?

~Arpit

Ümit Seren

unread,
Oct 16, 2014, 5:04:51 AM10/16/14
to gwt-pl...@googlegroups.com
I am also using this approach. Acutally I am not only loading the maps-api but also the charts api. 

The problem with this appraoch is that from a web-performance point of view it is really bad. You will get a blank screen until all the libraries are loaded. For example in my case it takes around 5 sec until placeManager.revealCurrentPlace() is called. 

I think the better appraoch would be not to block placeManager.revealCurrentPlace() but to go ahead and load the corresponding Presenter/View and defer the access to the maps API until it is loaded. This can be done with an Event that is fired on a global eventbus. Of course this is more involved because you have to store some kind of a state in the Presenter (api loaded) and handle the event instead of just drawing the map in the onReset() method. 

Richard Wallis

unread,
Oct 16, 2014, 5:17:43 AM10/16/14
to gwt-pl...@googlegroups.com
Yes I agree, the preload pattern won't perform well but it was simplest for the demo.

The example is not from maps but I would wrap all the calls in a callback similar to the following delayed method:

    public void get(final String item, final AsyncCallback<String> callback) {
        if (!ready) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    get(item, callback);

                }
            });
        } else {
            callback.onSuccess(get(item));
        }
    }

ready is a boolean that's set once a a required library is loaded.  So the method continually recalls itself until the result can be returned.
Reply all
Reply to author
Forward
0 new messages