Revision: 3717
          http://vexi.svn.sourceforge.net/vexi/?rev=3717&view=rev
Author:   mkpg2
Date:     2009-10-22 10:48:05 +0000 (Thu, 22 Oct 2009)

Log Message:
-----------
syncTransform - synchronise properties with different representations.

Modified Paths:
--------------
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t
    trunk/widgets/org.vexi.widgets/src/vexi/util/sync.t

Added Paths:
-----------
    trunk/widgets/org.vexi.widgets/src_vunit/test/util/sync.t

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t 
2009-10-21 17:39:30 UTC (rev 3716)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t 
2009-10-22 10:48:05 UTC (rev 3717)
@@ -22,7 +22,7 @@
         var model = {};
         
         // the focus list for this surface
-        var fvector = .util.vector..newVector();
+        var fvector = new .util.vector();
         
         // access to the model and current focus
         model.focus ++= .util.common..readOnly;

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t 2009-10-21 
17:39:30 UTC (rev 3716)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t 2009-10-22 
10:48:05 UTC (rev 3717)
@@ -88,7 +88,7 @@
         
     <ui:box align="topleft" orient="vertical" vshrink="true"
         highlightcolor="white" highlightfill="darkblue">
-
+               
         // use vars for encapsulation and efficiency
         var blockargs = [thisbox, thisbox];
         

Modified: trunk/widgets/org.vexi.widgets/src/vexi/util/sync.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/vexi/util/sync.t 2009-10-21 17:39:30 UTC 
(rev 3716)
+++ trunk/widgets/org.vexi.widgets/src/vexi/util/sync.t 2009-10-22 10:48:05 UTC 
(rev 3717)
@@ -62,6 +62,34 @@
         b[kb] --= writeB;
     };
     
+    // almost identical 
+    static.syncTransform = function(a,b,ka,kb,a2b,b2a){
+        if(!kb) kb = ka;
+        var fromA = false;
+        var fromB = false;
+        
+        var writeA = function(v) {
+            cascade = v;
+            if(fromB) return;
+            fromA = true;
+            try { b[kb] = a2b(v); } 
+            finally { fromA = false; }
+        };
+        
+        var writeB = function(v) {
+            cascade = v;
+            if(fromA) return;
+            fromB = true;
+            try { a[ka] = b2a(v); } 
+            finally { fromB = false; }
+        };
+        
+        a[ka] ++= writeA;
+        b[kb] ++= writeB;
+        return [a,b,ka,kb,writeA,writeB];
+    }; 
+    
+    
     <js:Object />
     
 </vexi>

Added: trunk/widgets/org.vexi.widgets/src_vunit/test/util/sync.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src_vunit/test/util/sync.t                   
        (rev 0)
+++ trunk/widgets/org.vexi.widgets/src_vunit/test/util/sync.t   2009-10-22 
10:48:05 UTC (rev 3717)
@@ -0,0 +1,46 @@
+<vexi xmlns:meta="vexi://meta" xmlns:ui="vexi://ui" xmlns="vexi" 
xmlns:sync="vexi.util.sync">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+    </meta:doc>
+    
+    <ui:box>
+        var assertEq = .test.vunit..assertEq;
+        var assertObjEq = .test.vunit..assertObjectEquals;
+        
+        { // normal
+            var a = {x: "a"};
+               var b = {y: "b"};
+               var token = sync..sync(a, b, "x", "y");
+               
+               assertEq("a",a.x);
+               assertEq("b",b.y);
+               a.x = "c";
+               assertEq("c",a.x);
+               assertEq("c",b.y);
+               
+               sync..unsync(token);
+               a.x = "d";
+               assertEq("d",a.x);
+               assertEq("c",b.y);
+        }
+        
+        { // transform
+            var a = {x: "a.b"};
+               var b = {y: []};
+               var a2b = function(s){ return s.split("."); };
+               var b2a = function(a){ return a.join("."); };
+            var token = sync..syncTransform(a, b, "x", "y", a2b, b2a);
+            
+            assertObjEq("a.b",a.x);
+            assertObjEq([],b.y);
+            a.x = a.x;
+            assertObjEq(["a","b"],b.y);
+            b.y = ["c","d"];
+            assertEq("c.d",a.x);
+            
+            sync..unsync(token);
+            a.x = "e.f";
+               assertObjEq(["c","d"],b.y);
+        }
+    </ui:box>
+</vexi>
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to