Author: jmorliaguet
Date: Sat Feb 25 15:17:08 2006
New Revision: 2457

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

- we compare the new data to store with the old data to avoid firing an event
  for nothing if the data is the same.



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 Sat Feb 25 
15:17:08 2006
@@ -95,7 +95,7 @@
     var subscribers = CPSSkins._subscribers;
     if (!(eventid in subscribers)) { return; }
     subscribers[eventid] = subscribers[eventid].reject(function(e) {
-      if (typeof event == 'undefined') return true;
+      if (event == undefined) return true;
       return (event.subscriber == e.subscriber &&
               event.publisher == e.publisher)
       });
@@ -1069,19 +1069,19 @@
         var next = this._queue[0];
         if (next in this._queued_data) {
           data = this._queued_data[next];
-          stored = this._writeFields(data);
+          stored = this._storeFields(data);
           this._queue.shift();
         } else {
           break;
         }
       }
     } else {
-      stored = this._writeFields(data);
+      stored = this._storeFields(data);
     }
     return stored;
   },
 
-  _writeFields: function(data) {
+  _storeFields: function(data) {
     // filter out fields with the wrong data type
     var schema = this.model.schema;
     var filtered_data = new Object();
@@ -1092,12 +1092,17 @@
         filtered_data[field] = value;
       }
     });
-    // TODO compare old and new data
-    this.model.def.data = filtered_data;
-    CPSSkins.notify('stored', {'publisher': this});
+    if (!this._compareData(this.model.def.data, filtered_data)) {;
+      this.model.def.data = filtered_data;
+      CPSSkins.notify('stored', {'publisher': this});
+    }
     return filtered_data;
   },
 
+  _compareData: function(a, b) {
+    return JSON.stringify(a) == JSON.stringify(b);
+  },
+
   merge: function(data) {
     var current_data = this.read();
     var new_data = $H(current_data).merge(data);
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to