Revision: 4096
          http://vexi.svn.sourceforge.net/vexi/?rev=4096&view=rev
Author:   clrg
Date:     2011-03-28 17:40:04 +0000 (Mon, 28 Mar 2011)

Log Message:
-----------
Add org.vexi.lib.util and move redirect there TODO clean up rest of vexi.util

Modified Paths:
--------------
    trunk/org.vexi-vexi.widgets/src_main/vexi/util/redirect.t

Added Paths:
-----------
    trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/util/
    trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/util/redirect.t

Copied: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/util/redirect.t (from 
rev 4057, trunk/org.vexi-vexi.widgets/src_main/vexi/util/redirect.t)
===================================================================
--- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/util/redirect.t           
                (rev 0)
+++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/util/redirect.t   
2011-03-28 17:40:04 UTC (rev 4096)
@@ -0,0 +1,157 @@
+<!-- Copyright 2009 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+    </meta:doc>
+    
+    var reportCollision = function(p, m) {
+        if (vexi.debug) {
+            vexi.trace(new vexi.js.Exception(m));
+        }
+    }
+    
+    /** write function for the main box of a full redirect */
+    var mainWrite = function(v) {
+        if (!trapee.redirect_lockfrom[trapname]) {
+            trapee.redirect_lock[trapname] = true;
+            trapee.redirect_to[trapname][trapname] = v;
+            trapee.redirect_lock[trapname] = null;
+        }
+        return true;
+    }
+    
+    /** read function for the main box of a full redirect */
+    var mainRead = function() {
+        return trapee.redirect_to[trapname][trapname];
+    }
+    
+    /** write function for the target box of a full redirect */
+    var targWrite = function(v) {
+        cascade = v;
+        var from = trapee.redirect_from[trapname];
+        if (!from.redirect_lock[trapname]) {
+            from.redirect_lockfrom[trapname] = true;
+            try {
+                from[trapname] = v;
+            } finally {
+                from.redirect_lockfrom[trapname] = null;
+            }
+        }
+    }
+    
+    /** add a redirect from b1[p] to b2[p] and return 'funcs' function list 
for later removal */
+    static.add = function(b1, b2, p) {
+        // create box reference from b1 to b2
+        if (b1.redirect_to and b1.redirect_to[p]) {
+            reportCollision(p, "Redirected property '"+p+"' more than once 
from a particular box");
+            static.drop(b1, p);
+        }
+        if (!b1.redirect_to) {
+            b1.redirect_to = {};
+        }
+        b1.redirect_to[p] = b2;
+        
+        // hash for locking property redirects
+        if (!b1.redirect_lock) {
+            b1.redirect_lock = {};
+            b1.redirect_lockfrom = {};
+        }
+        
+        // create box reference from b2 to b1
+        if (b2.redirect_from and b2.redirect_from[p]) {
+            reportCollision(p, "Redirected property '"+p+"' to same 
destination box more than once");
+            static.drop(b2.redirect_from[p], p);
+        }
+        if (!b2.redirect_from) {
+            b2.redirect_from = {};
+        }
+        b2.redirect_from[p] = b1;
+        
+        // wrap in try/catch clauses in case target properties don't allow 
trapping
+        try {
+            b1[p] ++= mainWrite;
+            // b1[p] already redirected to - ensure targWrite happens first
+            if (b1.redirect_from and b1.redirect_from[p]) {
+                b1[p] --= targWrite;
+                b1[p] ++= targWrite;
+            }
+            b1[p] ++= mainRead;
+            b2[p] ++= targWrite;
+        // clean up in the event of failure
+        } catch(e) {
+            var m = "Redirect failed on property '"+p+"' with error: 
"+e.message;
+            if (vexi.debug) {
+                throw m;
+            } else {
+                vexi.log.warn(m);
+            }
+            b1[p] --= mainWrite;
+            b1[p] --= mainRead;
+            b2[p] --= targWrite;
+        }
+    }
+    
+    /** drop set of redirect functions 'funcs' from 'b[p]' */
+    static.drop = function(b1, p) {
+        var b2 = b1.redirect_to[p];
+        // remove any traps
+        b1[p] --= mainWrite;
+        b1[p] --= mainRead;
+        b2[p] --= targWrite;
+        
+        // clean up references for b1
+        b1.redirect_to[p] = null;
+        var count = 0;
+        for (var key in b1.redirect_to) {
+            count++;
+            break;
+        }
+        if (count == 0) {
+            b1.redirect_to = null;
+            b1.redirect_lock = null;
+        }
+        
+        // clean up references for b2
+        b2.redirect_from[p] = null;
+        count = 0;
+        for (var key in b2.redirect_from) {
+            count++;
+            break;
+        }
+        if (count == 0) {
+            b2.redirect_from = null;
+        }
+    }
+    
+    /** add redirects 'arguments[2+]' from a to b */
+    static.addRedirect = function(a, b) {
+        if (a == null) {
+            throw "Tried to redirect from a null box or object";
+        }
+        if (b == null) {
+            throw "Tried to redirect to a null box or object";
+        }
+        if (a == b) {
+            throw "Redirects must be between two different boxes";
+        }
+        for (var i=2; arguments.length>i; i++) {
+            static.add(a, b, arguments[i]);
+        }
+    }
+    
+    /** delete redirects 'arguments[1+]' from box v */
+    static.delRedirect = function(v) {
+        for (var i=1; arguments.length>i; i++) {
+            static.drop(v, arguments[i]);
+        }
+    }
+    
+    <ui:box>
+        
+        // assign functions
+        thisbox.addRedirect = static.addRedirect;
+        thisbox.delRedirect = static.delRedirect;
+        
+    </ui:box>
+</vexi>

Modified: trunk/org.vexi-vexi.widgets/src_main/vexi/util/redirect.t
===================================================================
--- trunk/org.vexi-vexi.widgets/src_main/vexi/util/redirect.t   2011-03-28 
17:39:12 UTC (rev 4095)
+++ trunk/org.vexi-vexi.widgets/src_main/vexi/util/redirect.t   2011-03-28 
17:40:04 UTC (rev 4096)
@@ -1,157 +1,21 @@
-<!-- Copyright 2009 - see COPYING for details [LGPL] -->
+<!-- Copyright 2011 - see COPYING for details [LGPL] -->
 
-<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta">
+<vexi xmlns:meta="vexi://meta" xmlns="org.vexi.lib.util">
     <meta:doc>
         <author>Charles Goodwin</author>
+        <about>
+            Redirect puts and reads on box properties
+        </about>
+        <usage>
+            Preapply or access from static:
+              - addRedirect(boxA, boxB, "prop1", "prop2",... "propn");
+              - delRedirect(boxA, "prop1", "propn");
+        </usage>
     </meta:doc>
     
-    var reportCollision = function(p, m) {
-        if (vexi.debug) {
-            vexi.trace(new vexi.js.Exception(m));
-        }
-    }
+    <redirect />
     
-    /** write function for the main box of a full redirect */
-    var mainWrite = function(v) {
-        if (!trapee.redirect_lockfrom[trapname]) {
-            trapee.redirect_lock[trapname] = true;
-            trapee.redirect_to[trapname][trapname] = v;
-            trapee.redirect_lock[trapname] = null;
-        }
-        return true;
-    }
+    static.addRedirect = .redirect..addRedirect;
+    static.delRedirect = .redirect..delRedirect;
     
-    /** read function for the main box of a full redirect */
-    var mainRead = function() {
-        return trapee.redirect_to[trapname][trapname];
-    }
-    
-    /** write function for the target box of a full redirect */
-    var targWrite = function(v) {
-        cascade = v;
-        var from = trapee.redirect_from[trapname];
-        if (!from.redirect_lock[trapname]) {
-            from.redirect_lockfrom[trapname] = true;
-            try {
-                from[trapname] = v;
-            } finally {
-                from.redirect_lockfrom[trapname] = null;
-            }
-        }
-    }
-    
-    /** add a redirect from b1[p] to b2[p] and return 'funcs' function list 
for later removal */
-    static.add = function(b1, b2, p) {
-        // create box reference from b1 to b2
-        if (b1.redirect_to and b1.redirect_to[p]) {
-            reportCollision(p, "Redirected property '"+p+"' more than once 
from a particular box");
-            static.drop(b1, p);
-        }
-        if (!b1.redirect_to) {
-            b1.redirect_to = {};
-        }
-        b1.redirect_to[p] = b2;
-        
-        // hash for locking property redirects
-        if (!b1.redirect_lock) {
-            b1.redirect_lock = {};
-            b1.redirect_lockfrom = {};
-        }
-        
-        // create box reference from b2 to b1
-        if (b2.redirect_from and b2.redirect_from[p]) {
-            reportCollision(p, "Redirected property '"+p+"' to same 
destination box more than once");
-            static.drop(b2.redirect_from[p], p);
-        }
-        if (!b2.redirect_from) {
-            b2.redirect_from = {};
-        }
-        b2.redirect_from[p] = b1;
-        
-        // wrap in try/catch clauses in case target properties don't allow 
trapping
-        try {
-            b1[p] ++= mainWrite;
-            // b1[p] already redirected to - ensure targWrite happens first
-            if (b1.redirect_from and b1.redirect_from[p]) {
-                b1[p] --= targWrite;
-                b1[p] ++= targWrite;
-            }
-            b1[p] ++= mainRead;
-            b2[p] ++= targWrite;
-        // clean up in the event of failure
-        } catch(e) {
-            var m = "Redirect failed on property '"+p+"' with error: 
"+e.message;
-            if (vexi.debug) {
-                throw m;
-            } else {
-                vexi.log.warn(m);
-            }
-            b1[p] --= mainWrite;
-            b1[p] --= mainRead;
-            b2[p] --= targWrite;
-        }
-    }
-    
-    /** drop set of redirect functions 'funcs' from 'b[p]' */
-    static.drop = function(b1, p) {
-        var b2 = b1.redirect_to[p];
-        // remove any traps
-        b1[p] --= mainWrite;
-        b1[p] --= mainRead;
-        b2[p] --= targWrite;
-        
-        // clean up references for b1
-        b1.redirect_to[p] = null;
-        var count = 0;
-        for (var key in b1.redirect_to) {
-            count++;
-            break;
-        }
-        if (count == 0) {
-            b1.redirect_to = null;
-            b1.redirect_lock = null;
-        }
-        
-        // clean up references for b2
-        b2.redirect_from[p] = null;
-        count = 0;
-        for (var key in b2.redirect_from) {
-            count++;
-            break;
-        }
-        if (count == 0) {
-            b2.redirect_from = null;
-        }
-    }
-    
-    /** add redirects 'arguments[2+]' from a to b */
-    static.addRedirect = function(a, b) {
-        if (a == null) {
-            throw "Tried to redirect from a null box or object";
-        }
-        if (b == null) {
-            throw "Tried to redirect to a null box or object";
-        }
-        if (a == b) {
-            throw "Redirects must be between two different boxes";
-        }
-        for (var i=2; arguments.length>i; i++) {
-            static.add(a, b, arguments[i]);
-        }
-    }
-    
-    /** delete redirects 'arguments[1+]' from box v */
-    static.delRedirect = function(v) {
-        for (var i=1; arguments.length>i; i++) {
-            static.drop(v, arguments[i]);
-        }
-    }
-    
-    <ui:box>
-        
-        // assign functions
-        thisbox.addRedirect = static.addRedirect;
-        thisbox.delRedirect = static.delRedirect;
-        
-    </ui:box>
 </vexi>


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

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and publish 
your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to