cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [05/13] js commit: [all] Make pluginloader call a callback instead of firing a channel.
Date Tue, 30 Jul 2013 18:58:12 GMT
[all] Make pluginloader call a callback instead of firing a channel.


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/0df3426f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/0df3426f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/0df3426f

Branch: refs/heads/master
Commit: 0df3426f2bbfd7e919eec82776d8400665a1660e
Parents: c7839ae
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Tue Jul 30 10:24:11 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Jul 30 10:24:11 2013 -0400

----------------------------------------------------------------------
 lib/common/pluginloader.js | 24 ++++++++----------------
 lib/scripts/bootstrap.js   |  5 ++++-
 2 files changed, 12 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0df3426f/lib/common/pluginloader.js
----------------------------------------------------------------------
diff --git a/lib/common/pluginloader.js b/lib/common/pluginloader.js
index 19f84bb..18e9a0b 100644
--- a/lib/common/pluginloader.js
+++ b/lib/common/pluginloader.js
@@ -19,7 +19,6 @@
  *
 */
 
-var channel = require('cordova/channel');
 var modulemapper = require('cordova/modulemapper');
 
 // Helper function to inject a <script> tag.
@@ -32,7 +31,7 @@ function injectScript(url, onload, onerror) {
     document.head.appendChild(script);
 }
 
-function onScriptLoadingComplete(moduleList) {
+function onScriptLoadingComplete(moduleList, finishPluginLoading) {
     // Loop through all the plugins and then through their clobbers and merges.
     for (var i = 0, module; module = moduleList[i]; i++) {
         if (module) {
@@ -65,18 +64,11 @@ function onScriptLoadingComplete(moduleList) {
     finishPluginLoading();
 }
 
-// Called when:
-// * There are plugins defined and all plugins are finished loading.
-// * There are no plugins to load.
-function finishPluginLoading() {
-    channel.onPluginsReady.fire();
-}
-
 // Handler for the cordova_plugins.js content.
 // See plugman's plugin_loader.js for the details of this object.
 // This function is only called if the really is a plugins array that isn't empty.
 // Otherwise the onerror response handler will just call finishPluginLoading().
-function handlePluginsObject(path, moduleList) {
+function handlePluginsObject(path, moduleList, finishPluginLoading) {
     // Now inject the scripts.
     var scriptCounter = moduleList.length;
 
@@ -86,7 +78,7 @@ function handlePluginsObject(path, moduleList) {
     }
     function scriptLoadedCallback() {
         if (!--scriptCounter) {
-            onScriptLoadingComplete(moduleList);
+            onScriptLoadingComplete(moduleList, finishPluginLoading);
         }
     }
 
@@ -95,17 +87,17 @@ function handlePluginsObject(path, moduleList) {
     }
 }
 
-function injectPluginScript(pathPrefix) {
+function injectPluginScript(pathPrefix, finishPluginLoading) {
     injectScript(pathPrefix + 'cordova_plugins.js', function(){
         try {
             var moduleList = require("cordova/plugin_list");
-            handlePluginsObject(pathPrefix, moduleList);
+            handlePluginsObject(pathPrefix, moduleList, finishPluginLoading);
         } catch (e) {
             // Error loading cordova_plugins.js, file not found or something
             // this is an acceptable error, pre-3.0.0, so we just move on.
             finishPluginLoading();
         }
-    },finishPluginLoading); // also, add script load error handler for file not found
+    }, finishPluginLoading); // also, add script load error handler for file not found
 }
 
 function findCordovaPath() {
@@ -125,12 +117,12 @@ function findCordovaPath() {
 // Tries to load all plugins' js-modules.
 // This is an async process, but onDeviceReady is blocked on onPluginsReady.
 // onPluginsReady is fired when there are no plugins to load, or they are all done.
-exports.load = function() {
+exports.load = function(callback) {
     var pathPrefix = findCordovaPath();
     if (pathPrefix === null) {
         console.log('Could not find cordova.js script tag. Plugin loading may fail.');
         pathPrefix = '';
     }
-    injectPluginScript(pathPrefix);
+    injectPluginScript(pathPrefix, callback);
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0df3426f/lib/scripts/bootstrap.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap.js b/lib/scripts/bootstrap.js
index 197816d..1d797e9 100644
--- a/lib/scripts/bootstrap.js
+++ b/lib/scripts/bootstrap.js
@@ -100,6 +100,10 @@
         channel.onNativeReady.fire();
     }
 
+    pluginloader.load(function() {
+        channel.onPluginsReady.fire();
+    });
+
     /**
      * Create all cordova objects once native side is ready.
      */
@@ -122,5 +126,4 @@
 
     }, platformInitChannelsArray);
 
-    pluginloader.load();
 }(window));


Mime
View raw message