incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bcur...@apache.org
Subject git commit: [CB-299] cordova.js should allow for registering plugins as required before deviceready fires. Use for CupcakeStorage on Android.
Date Wed, 14 Mar 2012 23:02:09 GMT
Updated Branches:
  refs/heads/master e71e51e88 -> efdcd7703


[CB-299] cordova.js should allow for registering plugins as required before deviceready fires.
 Use for CupcakeStorage on Android.


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/efdcd770
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/efdcd770
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/efdcd770

Branch: refs/heads/master
Commit: efdcd770398b6ce79be90c809c240d6afccafaa8
Parents: e71e51e
Author: Bryce Curtis <curtis.bryce@gmail.com>
Authored: Wed Mar 14 18:01:59 2012 -0500
Committer: Bryce Curtis <curtis.bryce@gmail.com>
Committed: Wed Mar 14 18:01:59 2012 -0500

----------------------------------------------------------------------
 lib/bootstrap.js              |    8 +---
 lib/channel.js                |   65 +++++++++++++++++++++++++++++++++++-
 lib/plugin/android/storage.js |    4 ++
 3 files changed, 70 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/efdcd770/lib/bootstrap.js
----------------------------------------------------------------------
diff --git a/lib/bootstrap.js b/lib/bootstrap.js
index f90871b..dfc1a90 100755
--- a/lib/bootstrap.js
+++ b/lib/bootstrap.js
@@ -1,10 +1,5 @@
 (function (context) {
     var channel = require("cordova/channel"),
-        /**
-         * cordova Channels that must fire before "deviceready" is fired.
-         */ 
-        deviceReadyChannelsArray = [channel.onCordovaReady, channel.onCordovaInfoReady, channel.onCordovaConnectionReady],
-        deviceReadyChannelsMap = {},
         _self = {
             boot: function () {
                 //---------------
@@ -48,11 +43,12 @@
                         
                         // Fire the onresume event, since first one happens before JavaScript
is loaded
                         channel.onResume.fire();
-                    }, deviceReadyChannelsArray);
+                    }, channel.deviceReadyChannelsArray);
                     
                 }, [ channel.onDOMContentLoaded, channel.onNativeReady ]);
             }
         };
+        
     // boot up once native side is ready
     channel.onNativeReady.subscribeOnce(_self.boot);
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/efdcd770/lib/channel.js
----------------------------------------------------------------------
diff --git a/lib/channel.js b/lib/channel.js
old mode 100644
new mode 100755
index 9beed93..baf08b6
--- a/lib/channel.js
+++ b/lib/channel.js
@@ -46,6 +46,45 @@ var Channel = function(type, opts) {
         create: function (type, opts) {
             channel[type] = new Channel(type, opts);
             return channel[type];
+        },
+
+        /**
+         * cordova Channels that must fire before "deviceready" is fired.
+         */ 
+        deviceReadyChannelsArray: [],
+        deviceReadyChannelsMap: {},
+        
+        /**
+         * Indicate that a feature needs to be initialized before it is ready to be used.
+         * This holds up Cordova's "deviceready" event until the feature has been initialized
+         * and Cordova.initComplete(feature) is called.
+         *
+         * @param feature {String}     The unique feature name
+         */
+        waitForInitialization: function(feature) {
+            if (feature) {
+                var c = null;
+                if (this[feature]) {
+                    c = this[feature];
+                }
+                else {
+                    c = this.create(feature);
+                }
+                this.deviceReadyChannelsMap[feature] = c;
+                this.deviceReadyChannelsArray.push(c);
+            }
+        },
+
+        /**
+         * Indicate that initialization code has completed and the feature is ready to be
used.
+         *
+         * @param feature {String}     The unique feature name
+         */
+        initializationComplete: function(feature) {
+            var c = this.deviceReadyChannelsMap[feature];
+            if (c) {
+                c.fire();
+            }
         }
     },
     utils = require('cordova/utils');
@@ -131,14 +170,38 @@ Channel.prototype.fire = function(e) {
 };
 
 //HACK: defining them here so they are ready super fast!
+
+// DOM event that is received when the web page is loaded and parsed.
 channel.create('onDOMContentLoaded');
+
+// Event to indicate the Cordova native side is ready.
 channel.create('onNativeReady');
+
+// Event to indicate that all Cordova JavaScript objects have been created
+// and it's time to run plugin constructors.
 channel.create('onCordovaReady');
+
+// Event to indicate that device properties are available
 channel.create('onCordovaInfoReady');
+
+// Event to indicate that the connection property has been set.
 channel.create('onCordovaConnectionReady');
+
+// Event to indicate that Cordova is ready
+channel.create('onDeviceReady');
+
+// Event to indicate a resume lifecycle event
 channel.create('onResume');
+
+// Event to indicate a pause lifecycle event
 channel.create('onPause');
-channel.create('onDeviceReady');
+
+// Event to indicate a destroy lifecycle event
 channel.create('onDestroy');
 
+// Channels that must fire before "deviceready" is fired.
+channel.waitForInitialization('onCordovaReady');
+channel.waitForInitialization('onCordovaInfoReady');
+channel.waitForInitialization('onCordovaConnectionReady');
+
 module.exports = channel;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/efdcd770/lib/plugin/android/storage.js
----------------------------------------------------------------------
diff --git a/lib/plugin/android/storage.js b/lib/plugin/android/storage.js
index 11bef71..000612b 100644
--- a/lib/plugin/android/storage.js
+++ b/lib/plugin/android/storage.js
@@ -1,5 +1,6 @@
 var utils = require('cordova/utils'),
     exec = require('cordova/exec');
+    channel = require('cordova/channel');
 
 var queryQueue = {};
 
@@ -287,6 +288,8 @@ var DroidDB_openDatabase = function(name, version, display_name, size)
{
  * @constructor
  */
 var CupcakeLocalStorage = function() {
+    channel.waitForInitialization("cupcakeStorage");
+
     try {
 
       this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440);
@@ -305,6 +308,7 @@ var CupcakeLocalStorage = function() {
               storage[result.rows.item(i)['id']] =  result.rows.item(i)['body'];
             }
             setLength(result.rows.length);
+            channel.initializationComplete("cupcakeStorage");
           });
 
         },


Mime
View raw message