Author: jmorliaguet
Date: Sun Mar  5 21:40:05 2006
New Revision: 2534

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
Log:

- added a scope for each parser "initialized" event (this fixes a race
  condition when several nodes are getting parsed simultaneously)



Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar  5 
21:40:05 2006
@@ -51,6 +51,7 @@
   _defs: $H({}),
 
   init: function() {
+    CPSSkins._setup();
     CPSSkins._parse(document);
   },
 
@@ -175,6 +176,9 @@
 
   /* Document parsing */
 
+  _setup: function() {
+  },
+
   _jsonParse: function(el, text) {
     var res = {};
     try {
@@ -195,18 +199,20 @@
     if (!length) {
       return;
     }
-    this._initialized[node] = 0;
-    var progress = new Object();
+    var progress = {'initialized': 0};
 
     this.registerEventHandler("initialized", progress, function(event) {
-      this._initialized[node] += 1;
-      if (this._initialized[node] >= length) {
+      var progress = event.scope;
+      progress.initialized += 1;
+      if (progress.initialized >= length) {
         CPSSkins._load(node);
-        CPSSkins.unsubscribe("initialized", {'subscriber': progress});
+        CPSSkins.unsubscribe("initialized", {'scope': progress});
         CPSSkins.notify("parsed", {'publisher': node});
       }
-    }.bind(this));
-    CPSSkins.subscribe("initialized", {'subscriber': progress});
+    });
+    CPSSkins.subscribe("initialized",
+      {'subscriber': progress, 'scope': progress}
+    );
 
     elements.each(function(el) {
       var url = el.getAttribute("cite");
@@ -214,7 +220,7 @@
         var options = {
           onComplete: function(req) {
             CPSSkins._eval(el, req.responseText);
-            CPSSkins.notify('initialized', {'publisher': el});
+            CPSSkins.notify('initialized', {'publisher': el, 'scope': 
progress});
           }
         };
         var parts = url.split('?');
@@ -227,7 +233,7 @@
         /* the definition is written inline */
         CPSSkins._eval(el, el.innerHTML);
         el.innerHTML = '';
-        CPSSkins.notify('initialized', {'publisher': el});
+        CPSSkins.notify('initialized', {'publisher': el, 'scope': progress});
       }
     });
   },
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to