Author: rbaxter85
Date: Tue May 15 21:56:14 2012
New Revision: 1338914
URL: http://svn.apache.org/viewvc?rev=1338914&view=rev
Log:
SHINDIG-1776
Committed For Matt Franklin
Fix for pubsub2 duplicate error on second navigation of site
Modified:
shindig/trunk/features/src/main/javascript/features/container.site.gadget/gadget_holder.js
shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js
Modified:
shindig/trunk/features/src/main/javascript/features/container.site.gadget/gadget_holder.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.site.gadget/gadget_holder.js?rev=1338914&r1=1338913&r2=1338914&view=diff
==============================================================================
---
shindig/trunk/features/src/main/javascript/features/container.site.gadget/gadget_holder.js
(original)
+++
shindig/trunk/features/src/main/javascript/features/container.site.gadget/gadget_holder.js
Tue May 15 21:56:14 2012
@@ -179,6 +179,8 @@ osapi.container.GadgetHolder.prototype.d
* @private
*/
osapi.container.GadgetHolder.prototype.doOaaIframeHtml_ = function() {
+ //Remove any prior container for the iframe id from the OpenAjax hub prior
to registering the new one
+ this.removeOaaContainer_(this.iframeId_);
new OpenAjax.hub.IframeContainer(
gadgets.pubsub2router.hub,
this.iframeId_,
@@ -206,6 +208,20 @@ osapi.container.GadgetHolder.prototype.d
);
};
+/**
+ * Removes the specified container from the registered pubsub2router hub
+ *
+ * @param {String} containerId the id of the container to remove from the hub
+ * @private
+ */
+osapi.container.GadgetHolder.prototype.removeOaaContainer_ =
function(containerId) {
+ var container = gadgets.pubsub2router.hub.getContainer(containerId);
+ //Null is returned from the getContainer function per the OpenAjax spec if
the container is not found
+ if(container) {
+ gadgets.pubsub2router.hub.removeContainer(container);
+ }
+};
+
/**
* @param {Object} gadgetInfo the JSON gadget description.
Modified:
shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js?rev=1338914&r1=1338913&r2=1338914&view=diff
==============================================================================
---
shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js
(original)
+++
shindig/trunk/features/src/test/javascript/features/container/gadget_holder_test.js
Tue May 15 21:56:14 2012
@@ -33,11 +33,13 @@ GadgetHolderTest.prototype.setUp = funct
this.containerUri = window.__CONTAINER_URI;
window.__CONTAINER_URI = shindig.uri('http://container.com');
this.gadgetsRpc = gadgets.rpc;
+ this.pubsub2router = gadgets.pubsub2router;
};
GadgetHolderTest.prototype.tearDown = function() {
window.__CONTAINER_URI = this.containerUri;
gadgets.rpc = this.gadgetsRpc;
+ gadgets.pubsub2router = this.pubsub2router;
};
GadgetHolderTest.prototype.testNew = function() {
@@ -130,6 +132,22 @@ GadgetHolderTest.prototype.testRenderWit
' ></iframe>',
element.innerHTML);
};
+GadgetHolderTest.prototype.testRemoveOaContainer_exisiting = function() {
+ var hub = this.setupMockPubsub2router(true);
+ var holder = new osapi.container.GadgetHolder();
+ var answer = 42;
+ holder.removeOaaContainer_(answer);
+ this.assertEquals(answer, hub.getCallArgs().g.id);
+ this.assertEquals(answer, hub.getCallArgs().r.container.passedId);
+};
+GadgetHolderTest.prototype.testRemoveOaContainer_nonexisting = function() {
+ var hub = this.setupMockPubsub2router(false);
+ var holder = new osapi.container.GadgetHolder();
+ var answer = 42;
+ holder.removeOaaContainer_(answer);
+ this.assertEquals(answer, hub.getCallArgs().g.id);
+ this.assertEquals("undefined", typeof hub.getCallArgs().r.container);
+};
GadgetHolderTest.prototype.setupGadgetsRpcSetupReceiver = function() {
gadgets.rpc = {
@@ -137,3 +155,24 @@ GadgetHolderTest.prototype.setupGadgetsR
}
};
};
+
+GadgetHolderTest.prototype.setupMockPubsub2router = function(existing) {
+ gadgets.pubsub2router = {
+ hub:(function () {
+ var getArgs = {}, removeArgs = {};
+ return{
+ getContainer:function (id) {
+ getArgs.id = id;
+ return existing ? {passedId:id} : null;
+ },
+ removeContainer:function (container) {
+ removeArgs.container = container;
+ },
+ getCallArgs:function () {
+ return {g:getArgs, r:removeArgs}
+ }
+ }
+ })()
+ };
+ return gadgets.pubsub2router.hub;
+};