Why deferStart? Freezing application inside desktop wrappers

You must Login before you can answer or comment on any questions.

Took a dive into the mobileweb SDK. Having trouble figuring out what exactly this deferStart function is for... some of the wrappers I'm attempting to use are getting stuck. Why wait until waiting.length is null instead of just using require?

deferStart: function() {
    if (loaded) {
        console.warn("app.js already loaded!");
    } else {
        var n = Math.round(Math.random()*1e12);
        waiting.push(n);
        return function() {
            var p = waiting.indexOf(n);
            ~p && waiting.splice(p, 1);
            loaded = 1;
            waiting.length || require(cfg.main || ["app.js"]);
        };
    }
}

1 Answer

Accepted Answer

Ti.deferStart() is a Mobile Web internal function I wrote that allows different systems (including modules) to initialize before app.js is executed.

Say you have a module that needs to asynchronously fetch some external dependencies, all it needs to do is call Ti.deferStart(), then when the dependencies have been resolved, execute the function returned by deferStart().

This is being used by the Google Maps implementation. They have their own async loading code and when it loads (or fails to load), the defer start handle will still be called.

This function will be renamed to Ti._deferStart() in a future release, probably v2.1.1.

— answered 11 months ago by Chris Barber
answer permalink
4 Comments
  • Appreciate you taking the time to explain. Will have to look into Google Maps implementation to see why it's not completing when wrapped.

    — commented 11 months ago by Tristan Roscoe

  • Definitely has something to do with Google Maps. Just commented out

    #'Ti/Map',
    #'Ti/Map/View',
    #'Ti/Map/Annotation',
    inside compiler.py and completed no problem.

    — commented 11 months ago by Tristan Roscoe

  • Ah, yes. So there is a bug in 2.0.2 where if you are offline or can't resolve Google Maps, the app would hang. For the very soon to be released v2.1.0, we rewrote the internals of the require() mechanism to allow error callbacks to be fired when things like Google Maps can't be loaded, thus you can load your app.

    Your fix to comment out those modules in the compiler.py is absolutely perfect! We do that all the time. In fact, for v2.2, we are going to remove that list of modules and make them auto-detected. :)

    — commented 11 months ago by Chris Barber

  • Show 1 more comment

Your Answer

This question has been locked and cannot accept new answers.