Author: jmorliaguet
Date: Wed Feb 15 12:22:40 2006
New Revision: 2384

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/latency/cpsskins_latency.pt
Log:

- implemented storage access sequences (in write mode):

  - queue: first-in first-out
  - stack: last-in first-out



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 Wed Feb 15 
12:22:40 2006
@@ -795,12 +795,12 @@
 
   // high-level I/O
   getData: function() {
-    this.storage.requestData(); /* asynchronous call */
+    this.storage.readTransaction(); /* asynchronous call */
     return this.storage.read();
   },
 
   setData: function(data) {
-    this.storage.storeData(data);
+    this.storage.writeTransaction(data);
   },
 
   // TODO: to rewrite: this might not work if called asynchronously.
@@ -871,6 +871,30 @@
   initialize: function(model) {
     this.model = model;
     this.setup();
+    this._queue = $A([]);
+    this._queued_data = $H({});
+  },
+
+  readTransaction: function(data) {
+    // TODO: implement a read access sequences
+    this.requestData();
+  },
+
+  writeTransaction: function(data) {
+    var access = this.model.def.storage.access;
+    if (access) {
+      switch (access.type) {
+        case 'queue': {
+          this._queue.push(data[access.signature]);
+          break;
+        }
+        case 'stack': {
+          this._queue.unshift(data[access.signature]);
+          break;
+        }
+      }
+    }
+    this.storeData(data);
   },
 
   /* Public API */
@@ -892,6 +916,27 @@
   },
 
   write: function(data) {
+    var access = this.model.def.storage.access;
+
+    if (access && access.type) {
+      var signature = data[access.signature];
+      this._queued_data[signature] = data;
+      while (this._queue) {
+        var next = this._queue[0];
+        if (next in this._queued_data) {
+          data = this._queued_data[next];
+          this._writeFields(data);
+          this._queue.shift();
+        } else {
+          break;
+        }
+      }
+    } else {
+      this._writeFields(data);
+    }
+  },
+
+  _writeFields: function(data) {
     // filter out fields with the wrong data type
     var schema = this.model.schema;
     var filtered_data = new Object();

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/latency/cpsskins_latency.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/latency/cpsskins_latency.pt
  (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/latency/cpsskins_latency.pt
  Wed Feb 15 12:22:40 2006
@@ -45,13 +45,13 @@
 
     function init() {
       run('no-sequence', 1);
-      run('stack-sequence', 2);
-      run('queue-sequence', 3);
+      run('queue-sequence', 2);
+      run('stack-sequence', 3);
     }
 
     function run(model_id, storage) {
       var model = CPSSkins.getModelById(model_id);
-      $R(1,20).each(function(v) {
+      $R(1,10).each(function(v) {
         model.setData({'storage': storage, 'position': v, 's': v});
       });
     }
@@ -166,7 +166,7 @@
         {"widget": {
            "type": "counter"
           },
-         "model": "stack-sequence"
+         "model": "queue-sequence"
         }
         </ins>
       </td>
@@ -176,7 +176,7 @@
         {"widget": {
            "type": "counter"
           },
-         "model": "queue-sequence"
+         "model": "stack-sequence"
         }
         </ins>
       </td>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to