incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryce Curtis <curtis.br...@gmail.com>
Subject Re: internal Cordova events doc'd? was: git commit: changing plugins that rely on exec during initialization ...
Date Fri, 30 Mar 2012 13:53:02 GMT
It used to be documented in phonegap.js.base, but I don't see it in
cordova-js anywhere.  Probably good to put in docs though.  Here's the
comment that used to be there.

/**
 * The order of events during page load and Cordova startup is as follows:
 *
 * onDOMContentLoaded         Internal event that is received when the web
page is loaded and parsed.
 * window.onload              Body onload event.
 * onNativeReady              Internal event that indicates the Cordova
native side is ready.
 * onCordovaInit             Internal event that kicks off creation of all
Cordova JavaScript objects (runs constructors).
 * onCordovaReady            Internal event fired when all Cordova
JavaScript objects have been created
 * onCordovaInfoReady        Internal event fired when device properties
are available
 * onCordovaConnectionReady  Internal event fired when the connection
property has been set.
 * onDeviceReady              User event fired to indicate that Cordova is
ready
 * onResume                   User event fired to indicate a start/resume
lifecycle event
 * onPause                    User event fired to indicate a pause
lifecycle event
 * onDestroy                  Internal event fired when app is being
destroyed (User should use window.onunload event, not this one).
 *
 * The only Cordova events that user code should register for are:
 *      deviceready           Cordova native code is initialized and
Cordova APIs can be called from JavaScript
 *      pause                 App has moved to background
 *      resume                App has returned to foreground
 *
 * Listeners can be registered as:
 *      document.addEventListener("deviceready", myDeviceReadyListener,
false);
 *      document.addEventListener("resume", myResumeListener, false);
 *      document.addEventListener("pause", myPauseListener, false);
 *
 * The DOM lifecycle events should be used for saving and restoring state
 *      window.onload
 *      window.onunload
 */


On Fri, Mar 30, 2012 at 6:56 AM, Patrick Mueller <pmuellr@gmail.com> wrote:

> Do we have these internal events like `onCordovaInfoReady` documented
> anywhere?  I think if someone asked me how these work today, I'd tell them
> to go look at the errgen platform, where I figured out what they all were
> by debugging/code scanning.
>
> I was kinda curious, and googled `onCordovaInfoReady`.  AND GOT HITS.  :-)
>
> Nothing documenting the events though :-(
>
> ---------- Forwarded message ----------
> From: <filmaj@apache.org>
> Date: Thu, Mar 29, 2012 at 19:21
> Subject: [3/3] git commit: changing plugins that rely on exec during
> initialization to attach first to CordovaReady, as the communication bridge
> may not be fully ready before this event fires.
> To: callback-commits@incubator.apache.org
>
>
> changing plugins that rely on exec during initialization to attach first to
> CordovaReady, as the communication bridge may not be fully ready before
> this event fires.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/d2fc7133
> Tree:
> http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/d2fc7133
> Diff:
> http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/d2fc7133
>
> Branch: refs/heads/master
> Commit: d2fc71333c12d1b13cdcae58b50eec26a82e3b30
> Parents: cddb3b8
> Author: Fil Maj <maj.fil@gmail.com>
> Authored: Thu Mar 29 16:12:25 2012 -0700
> Committer: Fil Maj <maj.fil@gmail.com>
> Committed: Thu Mar 29 16:12:25 2012 -0700
>
> ----------------------------------------------------------------------
>  lib/android/plugin/android/device.js       |    9 ++-
>  lib/blackberry/plugin/blackberry/device.js |   16 +++---
>  lib/common/plugin/network.js               |   73 ++++++++++++-----------
>  lib/playbook/plugin/playbook/device.js     |    7 +-
>  4 files changed, 54 insertions(+), 51 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/android/plugin/android/device.js
> ----------------------------------------------------------------------
> diff --git a/lib/android/plugin/android/device.js
> b/lib/android/plugin/android/device.js
> index 44a80c6..353d0ed 100644
> --- a/lib/android/plugin/android/device.js
> +++ b/lib/android/plugin/android/device.js
> @@ -16,8 +16,9 @@ function Device() {
>    this.cordova = null;
>
>    var me = this;
> -    this.getInfo(
> -        function(info) {
> +
> +    channel.onCordovaReady.subscribeOnce(function() {
> +        this.getInfo(function(info) {
>            me.available = true;
>            me.platform = info.platform;
>            me.version = info.version;
> @@ -25,11 +26,11 @@ function Device() {
>            me.uuid = info.uuid;
>            me.cordova = info.cordova;
>            channel.onCordovaInfoReady.fire();
> -        },
> -        function(e) {
> +        },function(e) {
>            me.available = false;
>            utils.alert("[ERROR] Error initializing Cordova: " + e);
>        });
> +    });
>  }
>
>  /**
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/blackberry/plugin/blackberry/device.js
> ----------------------------------------------------------------------
> diff --git a/lib/blackberry/plugin/blackberry/device.js
> b/lib/blackberry/plugin/blackberry/device.js
> index 42a0647..01b41e5 100644
> --- a/lib/blackberry/plugin/blackberry/device.js
> +++ b/lib/blackberry/plugin/blackberry/device.js
> @@ -2,8 +2,8 @@ var me = {},
>    channel = require('cordova/channel'),
>    exec = require('cordova/exec');
>
> -exec(
> -    function (device) {
> +channel.onCordovaReady.subscribeOnce(function() {
> +    exec(function (device) {
>        me.platform = device.platform;
>        me.version  = device.version;
>        me.name     = device.name;
> @@ -11,13 +11,13 @@ exec(
>        me.cordova  = device.cordova;
>
>        channel.onCordovaInfoReady.fire();
> -    },
> -    function (e) {
> +    },function (e) {
>        console.log("error initializing cordova: " + e);
>    },
> -    "Device",
> -    "getDeviceInfo",
> -    []
> -);
> +        "Device",
> +        "getDeviceInfo",
> +        []
> +    );
> +});
>
>  module.exports = me;
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/common/plugin/network.js
> ----------------------------------------------------------------------
> diff --git a/lib/common/plugin/network.js b/lib/common/plugin/network.js
> index 899aab5..f5b4fd4 100644
> --- a/lib/common/plugin/network.js
> +++ b/lib/common/plugin/network.js
> @@ -3,46 +3,47 @@ var exec = require('cordova/exec'),
>    channel = require('cordova/channel');
>
>  var NetworkConnection = function () {
> -        this.type = null;
> -        this._firstRun = true;
> -        this._timer = null;
> -        this.timeout = 500;
> +    this.type = null;
> +    this._firstRun = true;
> +    this._timer = null;
> +    this.timeout = 500;
>
> -        var me = this;
> +    var me = this;
>
> -        this.getInfo(
> -            function (info) {
> -                me.type = info;
> -                if (info === "none") {
> -                    // set a timer if still offline at the end of timer
> send the offline event
> -                    me._timer = setTimeout(function(){
> -                        cordova.fireDocumentEvent("offline");
> -                        me._timer = null;
> -                        }, me.timeout);
> -                } else {
> -                    // If there is a current offline event pending clear
> it
> -                    if (me._timer !== null) {
> -                        clearTimeout(me._timer);
> -                        me._timer = null;
> -                    }
> -                    cordova.fireDocumentEvent("online");
> +    channel.onCordovaReady.subscribeOnce(function() {
> +        me.getInfo(function (info) {
> +            me.type = info;
> +            if (info === "none") {
> +                // set a timer if still offline at the end of timer send
> the offline event
> +                me._timer = setTimeout(function(){
> +                    cordova.fireDocumentEvent("offline");
> +                    me._timer = null;
> +                    }, me.timeout);
> +            } else {
> +                // If there is a current offline event pending clear it
> +                if (me._timer !== null) {
> +                    clearTimeout(me._timer);
> +                    me._timer = null;
>                }
> +                cordova.fireDocumentEvent("online");
> +            }
>
> -                // should only fire this once
> -                if (me._firstRun) {
> -                    me._firstRun = false;
> -                    channel.onCordovaConnectionReady.fire();
> -                }
> -            },
> -            function (e) {
> -                // If we can't get the network info we should still tell
> Cordova
> -                // to fire the deviceready event.
> -                if (me._firstRun) {
> -                    me._firstRun = false;
> -                    channel.onCordovaConnectionReady.fire();
> -                }
> -                console.log("Error initializing Network Connection: " +
> e);
> -            });
> +            // should only fire this once
> +            if (me._firstRun) {
> +                me._firstRun = false;
> +                channel.onCordovaConnectionReady.fire();
> +            }
> +        },
> +        function (e) {
> +            // If we can't get the network info we should still tell
> Cordova
> +            // to fire the deviceready event.
> +            if (me._firstRun) {
> +                me._firstRun = false;
> +                channel.onCordovaConnectionReady.fire();
> +            }
> +            console.log("Error initializing Network Connection: " + e);
> +        });
> +    });
>  };
>
>  /**
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/playbook/plugin/playbook/device.js
> ----------------------------------------------------------------------
> diff --git a/lib/playbook/plugin/playbook/device.js
> b/lib/playbook/plugin/playbook/device.js
> index 90ec376..f3d86ec 100644
> --- a/lib/playbook/plugin/playbook/device.js
> +++ b/lib/playbook/plugin/playbook/device.js
> @@ -2,8 +2,8 @@ var me = {},
>    exec = require('cordova/exec'),
>    channel = require('cordova/channel');
>
> -exec(
> -    function (device) {
> +channel.onCordovaReady.subscribeOnce(function() {
> +    exec(function (device) {
>        me.platform = device.platform;
>        me.version  = device.version;
>        me.name     = device.name;
> @@ -18,6 +18,7 @@ exec(
>    "Device",
>    "getDeviceInfo",
>    []
> -);
> +    );
> +});
>
>  module.exports = me;
>
>
>
>
> --
> Patrick Mueller
> http://muellerware.org
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message