You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by jo...@apache.org on 2011/08/03 23:18:21 UTC

svn commit: r1153671 - in /shindig/trunk: config/ features/src/main/javascript/features/ features/src/main/javascript/features/deferjs/ features/src/main/javascript/features/exportjs/

Author: johnh
Date: Wed Aug  3 21:18:20 2011
New Revision: 1153671

URL: http://svn.apache.org/viewvc?rev=1153671&view=rev
Log:
Introduce feature deferJs(), which installs argument queueing stubs for features that support defer.

This reverts the exportJs() method signature's second argument to include namespace objects themselves, and removes the deferred symbol binding code from it. Code for actually executing enqueued methods remains, to work in concert with deferred.


Added:
    shindig/trunk/features/src/main/javascript/features/deferjs/
    shindig/trunk/features/src/main/javascript/features/deferjs/deferjs.js
    shindig/trunk/features/src/main/javascript/features/deferjs/feature.xml
Modified:
    shindig/trunk/config/container.js
    shindig/trunk/features/src/main/javascript/features/exportjs/exportjs.js
    shindig/trunk/features/src/main/javascript/features/features.txt

Modified: shindig/trunk/config/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/config/container.js?rev=1153671&r1=1153670&r2=1153671&view=diff
==============================================================================
--- shindig/trunk/config/container.js (original)
+++ shindig/trunk/config/container.js Wed Aug  3 21:18:20 2011
@@ -119,7 +119,7 @@
 "gadgets.uri.iframe.lockedDomainSuffix": "${Cur['defaultShindigTestAuthority']}",
 
 // Default Js Uri config: also must be overridden.
-"gadgets.uri.js.host": "//${Cur['defaultShindigTestAuthority']}",
+"gadgets.uri.js.host": "http://${Cur['defaultShindigTestAuthority']}",
 "gadgets.uri.js.path": "${CONTEXT_ROOT}/gadgets/js",
 
 // Default concat Uri config; used for testing.

Added: shindig/trunk/features/src/main/javascript/features/deferjs/deferjs.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/deferjs/deferjs.js?rev=1153671&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/deferjs/deferjs.js (added)
+++ shindig/trunk/features/src/main/javascript/features/deferjs/deferjs.js Wed Aug  3 21:18:20 2011
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+/**
+ * @fileoverview This provides a mechanism to defer JS symbols.
+ *
+ * Works in concert with exportJs() to bind dummy symbol names,
+ * provided as namespace + array of method names, which enqueue
+ * arguments passed to them. When a payload bundle of JS is loaded
+ * that defines the full implementation, exportJs() calls the
+ * deferred implementation dequeueing the enqueued arguments with
+ * the actual method.
+ */
+function deferJs(namespace, components) {
+  var JSL = '___jsl';
+  var DEFER_KEY = 'df';
+  var base = window;
+  var nsParts = namespace.split('.');
+  var sliceFn = [].slice;
+
+  // Set up defer function queue.
+  var deferMap = ((window[JSL] = window[JSL] || {})[DEFER_KEY] = window[JSL][DEFER_KEY] || {});
+
+  var part;
+  while (part = nsParts.shift()) {
+    base[part] = base[part] || {};
+    base = base[part];
+  }
+
+  var methods = sliceFn.call(components, 0);
+  var method;
+  while (method = methods.shift()) {
+    // Don't overwrite an existing method if present,
+    // whether deferred or full/exported.
+    if (!base[method]) {
+      var fulltok = namespace + '.' + method;
+      base[method] = (function() {
+        var queue = [];
+        var ret = function() {
+          queue.push(sliceFn.call(arguments, 0));
+        };
+        deferMap[fulltok] = function(ctx, method) {
+          for (var i = 0, len = queue.length; i < len; ++i) {
+            method.apply(ctx, queue[i]);
+          }
+        };
+        return ret;
+      })();
+    }
+  }
+}

Added: shindig/trunk/features/src/main/javascript/features/deferjs/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/deferjs/feature.xml?rev=1153671&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/deferjs/feature.xml (added)
+++ shindig/trunk/features/src/main/javascript/features/deferjs/feature.xml Wed Aug  3 21:18:20 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations under the License.
+-->
+<feature>
+  <name>deferjs</name>
+  <all>
+    <script src="deferjs.js"/>
+  </all>
+</feature>

Modified: shindig/trunk/features/src/main/javascript/features/exportjs/exportjs.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/exportjs/exportjs.js?rev=1153671&r1=1153670&r2=1153671&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/exportjs/exportjs.js (original)
+++ shindig/trunk/features/src/main/javascript/features/exportjs/exportjs.js Wed Aug  3 21:18:20 2011
@@ -47,38 +47,21 @@
  * gadgets.foo = {};
  * gadgets.foo.bar = function() { ... };
  *
- * Also supports deferred symbol binding. When deferred mode is specified,
- * undefined symbols being defined in context here are treated as functions
- * with no return value. Stub functions are created for them at the
- * specified named endpoint. These functions enqueue requests and immediately
- * return. When the real method implementation is loaded and exported,
- * the real method is executed with the enqueued arguments.
+ * Support for deferred symbol binding (via deferJs()) is also provided.
+ * A 'real' method is executed with the enqueued arguments when in deferMap.
  */
-function exportJs(namespace, components, opt_props, opt_defer) {
+function exportJs(namespace, components, opt_props) {
   var JSL = '___jsl';
   var DEFER_KEY = 'df';
   var base = window;
   var prevBase = null;
   var nsParts = namespace.split('.');
-  var sliceFn = [].slice;
 
   // Set up defer function queue.
   var deferMap = ((window[JSL] = window[JSL] || {})[DEFER_KEY] = window[JSL][DEFER_KEY] || {});
 
-  // TODO: Remove support for arrayStyle after a reasonable amount of time.
-  var arrayStyle = components.constructor === Array;
-
-  // New-style: object mapping. Doesn't require symbols be pre-defined.
-  // array/old-style supported only for transition; will be removed.
-  var rmap = {};
-  for (var rkey in components) {
-    if (components.hasOwnProperty(rkey)) {
-      rmap[components[rkey]] = rkey;
-    }
-  }
-
   for (var i = 0, part; part = nsParts.shift(); i++) {
-    base[part] = base[part] || (arrayStyle ? components[i] : base[rmap[part]]) || {};
+    base[part] = base[part] || components[i] || {};
     prevBase = base;
     base = base[part];
   }
@@ -101,26 +84,13 @@ function exportJs(namespace, components,
         if (root.hasOwnProperty(prop)) {
           if (!root[curalias]) {
             root[curalias] = root[prop];
-          } else if (!opt_defer && deferMap[fulltok]) {
+          } else if (deferMap[fulltok]) {
             // Executes enqueued requests for the method,
             // then replaces the export.
             deferMap[fulltok](root, root[prop]);
             delete deferMap[fulltok];
             root[curalias] = root[prop];
           }
-        } else if (opt_defer) {
-          root[prop] = (function() {
-            var queue = [];
-            var ret = function() {
-              queue.push(sliceFn.call(arguments, 0));
-            };
-            deferMap[fulltok] = function(ctx, method) {
-              for (var i = 0, len = queue.length; i < len; ++i) {
-                method.apply(ctx, queue[i]);
-              }
-            };
-            return ret;
-          })();
         }
       }
     }

Modified: shindig/trunk/features/src/main/javascript/features/features.txt
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/features.txt?rev=1153671&r1=1153670&r2=1153671&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/features.txt (original)
+++ shindig/trunk/features/src/main/javascript/features/features.txt Wed Aug  3 21:18:20 2011
@@ -48,6 +48,7 @@ features/core.util.string/feature.xml
 features/core.util.urlparams/feature.xml
 features/core/feature.xml
 features/defer.test/feature.xml
+features/deferjs/feature.xml
 features/dynamic-height.height/feature.xml
 features/dynamic-height.util/feature.xml
 features/dynamic-height/feature.xml