flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pio...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - Make clean up in all Binding classes - in order to have more readable code
Date Sat, 14 Jan 2017 20:02:53 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 443d8e4de -> ac1bf7a68


Make clean up in all Binding classes - in order to have more readable code


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/ac1bf7a6
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/ac1bf7a6
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/ac1bf7a6

Branch: refs/heads/develop
Commit: ac1bf7a685348ffa99592ea76fab187bcca9dd13
Parents: 443d8e4
Author: piotrz <piotrz@apache.org>
Authored: Sat Jan 14 21:02:48 2017 +0100
Committer: piotrz <piotrz@apache.org>
Committed: Sat Jan 14 21:02:48 2017 +0100

----------------------------------------------------------------------
 .../flex/binding/ApplicationDataBinding.as      | 106 ++++++++---------
 .../apache/flex/binding/ContainerDataBinding.as |   4 +-
 .../flex/binding/ItemRendererDataBinding.as     | 114 +++++++++----------
 .../flex/binding/MXMLBeadViewDataBinding.as     | 108 ++++++++----------
 4 files changed, 147 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ac1bf7a6/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ApplicationDataBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ApplicationDataBinding.as
b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ApplicationDataBinding.as
index e4130c9..438a809 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ApplicationDataBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ApplicationDataBinding.as
@@ -20,6 +20,7 @@ package org.apache.flex.binding
 {
     import org.apache.flex.binding.ConstantBinding;
     import org.apache.flex.binding.GenericBinding;
+    import org.apache.flex.core.IBinding;
     import org.apache.flex.binding.PropertyWatcher;
     import org.apache.flex.binding.SimpleBinding;
     import org.apache.flex.binding.WatcherBase;
@@ -79,18 +80,20 @@ package org.apache.flex.binding
 
         private function initCompleteHandler(event:Event):void
         {
-            var fieldWatcher:Object;
-            var sb:SimpleBinding;
             if (!("_bindings" in _strand))
                 return;
+
+            var fieldWatcher:Object;
+            var sb:SimpleBinding;
             var bindingData:Array = _strand["_bindings"];
             var n:int = bindingData[0];
             var bindings:Array = [];
+            var binding:Object = null;
             var i:int;
             var index:int = 1;
             for (i = 0; i < n; i++)
             {
-                var binding:Object = {};
+                binding = {};
                 binding.source = bindingData[index++];
 				binding.destFunc = bindingData[index++];
                 binding.destination = bindingData[index++];
@@ -99,20 +102,21 @@ package org.apache.flex.binding
             var watchers:Object = decodeWatcher(bindingData.slice(index));
             for (i = 0; i < n; i++)
             {
-                    binding = bindings[i];
+                binding = bindings[i];
                 if (binding.source is Array)
                 {
                     if (binding.source[0] in _strand)
                     {
                         if (binding.source.length == 2 && binding.destination.length
== 2)
                         {
-                            // simple component.property binding
-                            var destObject:Object;
-                            var destination:IStrand;
                             // can be simplebinding or constantbinding
                             var compWatcher:Object = watchers.watcherMap[binding.source[0]];
-                            fieldWatcher = compWatcher.children.watcherMap[binding.source[1]];
-                            if (fieldWatcher.eventNames is String)
+                            if (compWatcher)
+                            {
+                                fieldWatcher = compWatcher.children.watcherMap[binding.source[1]];
+                            }
+
+                            if (fieldWatcher && fieldWatcher.eventNames is String)
                             {
                                 sb = new SimpleBinding();
                                 sb.destinationPropertyName = binding.destination[1];
@@ -120,48 +124,18 @@ package org.apache.flex.binding
                                 sb.sourceID = binding.source[0];
                                 sb.sourcePropertyName = binding.source[1];
                                 sb.setDocument(_strand);
-                                destObject = _strand[binding.destination[0]];           
                    
-                                destination = destObject as IStrand;
-                                if (destination)
-                                    destination.addBead(sb);
-                                else
-                                {
-                                    if (destObject)
-                                    {
-                                        sb.destination = destObject;
-                                        _strand.addBead(sb);
-                                    }
-                                    else
-                                    {
-                                        deferredBindings[binding.destination[0]] = sb;
-                                        IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                                    }
-                                }
+
+                                prepareCreatedBinding(sb as IBinding, binding);
                             }
-                            else if (fieldWatcher.eventNames == null)
+                            else if (fieldWatcher && fieldWatcher.eventNames == null)
                             {
                                 var cb:ConstantBinding = new ConstantBinding();
                                 cb.destinationPropertyName = binding.destination[1];
                                 cb.sourceID = binding.source[0];
                                 cb.sourcePropertyName = binding.source[1];
                                 cb.setDocument(_strand);
-                                destObject = _strand[binding.destination[0]];           
                    
-                                destination = destObject as IStrand;
-                                if (destination)
-                                    destination.addBead(cb);
-                                else
-                                {
-                                    if (destObject)
-                                    {
-                                        cb.destination = destObject;
-                                        _strand.addBead(cb);
-                                    }
-                                    else
-                                    {
-                                        deferredBindings[binding.destination[0]] = cb;
-                                        IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                                    }
-                                }
+
+                                prepareCreatedBinding(cb as IBinding, binding);
                             }
                         }
                     }
@@ -176,29 +150,39 @@ package org.apache.flex.binding
                         sb.eventName = fieldWatcher.eventNames as String;
                         sb.sourcePropertyName = binding.source;
                         sb.setDocument(_strand);
-                        destObject = _strand[binding.destination[0]];                   
            
-                        destination = destObject as IStrand;
-                        if (destination)
-                            destination.addBead(sb);
-                        else
-                        {
-                            if (destObject)
-                            {
-                                sb.destination = destObject;
-                                _strand.addBead(sb);
-                            }
-                            else
-                            {
-                                deferredBindings[binding.destination[0]] = sb;
-                                IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                            }
-                        }
+
+                        prepareCreatedBinding(sb as IBinding, binding);
                     }
                 }
                 else
                 {
                     makeGenericBinding(binding, i, watchers);
                 }
+
+                fieldWatcher = null;
+            }
+        }
+
+        private function prepareCreatedBinding(binding:IBinding, bindingObject:Object):void
+        {
+            var destinationObject:Object = _strand[bindingObject.destination[0]];
+            var destination:IStrand = destinationObject as IStrand;
+            if (destination)
+            {
+                destination.addBead(binding as IBead);
+            }
+            else
+            {
+                if (destinationObject)
+                {
+                    binding.destination = destinationObject;
+                    _strand.addBead(binding as IBead);
+                }
+                else
+                {
+                    deferredBindings[bindingObject.destination[0]] = binding;
+                    IEventDispatcher(_strand).addEventListener("valueChange", deferredBindingsHandler);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ac1bf7a6/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ContainerDataBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ContainerDataBinding.as
b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ContainerDataBinding.as
index 92df8b5..1fc5977 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ContainerDataBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ContainerDataBinding.as
@@ -101,7 +101,7 @@ package org.apache.flex.binding
             var watchers:Object = decodeWatcher(bindingData.slice(index));
             for (i = 0; i < n; i++)
             {
-                    binding = bindings[i];
+                binding = bindings[i];
                 if (binding.source is Array)
                 {
                     if (binding.source[0] in _strand)
@@ -187,6 +187,8 @@ package org.apache.flex.binding
                 {
                     makeGenericBinding(binding, i, watchers);
                 }
+
+                fieldWatcher = null;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ac1bf7a6/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ItemRendererDataBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ItemRendererDataBinding.as
b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ItemRendererDataBinding.as
index 315a372..46301dc 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ItemRendererDataBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ItemRendererDataBinding.as
@@ -27,7 +27,8 @@ package org.apache.flex.binding
     import org.apache.flex.core.IStrand;
     import org.apache.flex.events.Event;
     import org.apache.flex.events.IEventDispatcher;
-    
+    import org.apache.flex.core.IBinding;
+
     /**
      *  The ItemRendererDataBinding class implements databinding for
      *  ItemRenderer instances.  Different classes can have
@@ -69,22 +70,28 @@ package org.apache.flex.binding
         public function set strand(value:IStrand):void
         {
             _strand = value;
-            var fieldWatcher:Object;
-            var isStatic:Boolean;
-            var sb:SimpleBinding;
+
+            IEventDispatcher(_strand).addEventListener("initBindings", initCompleteHandler);
+        }
+
+        private function initCompleteHandler(event:Event):void
+        {
             if (!("_bindings" in _strand))
                 return;
+
+            var fieldWatcher:Object;
+            var sb:SimpleBinding;
             var bindingData:Array = _strand["_bindings"];
-            var destObject:Object;
             var n:int = bindingData[0];
             var bindings:Array = [];
+            var binding:Object = null;
             var i:int;
             var index:int = 1;
             for (i = 0; i < n; i++)
             {
-                var binding:Object = {};
+                binding = {};
                 binding.source = bindingData[index++];
-				binding.destFunc = bindingData[index++];
+                binding.destFunc = bindingData[index++];
                 binding.destination = bindingData[index++];
                 bindings.push(binding);
             }
@@ -92,39 +99,31 @@ package org.apache.flex.binding
             for (i = 0; i < n; i++)
             {
                 binding = bindings[i];
-                var destination:IStrand;
 
                 if (binding.source is String)
                 {
                     fieldWatcher = watchers.watcherMap[binding.source];
-                    if (!fieldWatcher) makeConstantBinding(binding, _strand);
+                    if (!fieldWatcher)
+                    {
+                        makeConstantBinding(binding);
+                    }
                     else if (fieldWatcher.eventNames is String)
                     {
-                        isStatic = fieldWatcher.type == "static";
+                        var isStatic:Boolean = fieldWatcher.type == "static";
                         sb = new SimpleBinding(isStatic);
                         sb.destinationPropertyName = binding.destination[1];
                         sb.eventName = fieldWatcher.eventNames as String;
                         sb.sourcePropertyName = binding.source;
                         if (isStatic)
+                        {
                             sb.setDocument(fieldWatcher.parentObj);
-                        else sb.setDocument(_strand);
-                        destObject = _strand[binding.destination[0]];
-                        destination = destObject as IStrand;
-                        if (destination)
-                            destination.addBead(sb);
+                        }
                         else
                         {
-                            if (destObject)
-                            {
-                                sb.destination = destObject;
-                                _strand.addBead(sb);
-                            }
-                            else
-                            {
-                                deferredBindings[binding.destination[0]] = sb;
-                                IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                            }
+                            sb.setDocument(_strand);
                         }
+
+                        prepareCreatedBinding(sb as IBinding, binding);
                     }
                 }
                 else if (binding.source is Array
@@ -156,27 +155,12 @@ package org.apache.flex.binding
                         sb.sourceID = binding.source[0];
                         sb.sourcePropertyName = binding.source[1];
                         sb.setDocument(_strand);
-                        destObject = _strand[binding.destination[0]];                   
            
-                        destination = destObject as IStrand;
-                        if (destination)
-                            destination.addBead(sb);
-                        else
-                        {
-                            if (destObject)
-                            {
-                                sb.destination = destObject;
-                                _strand.addBead(sb);
-                            }
-                            else
-                            {
-                                deferredBindings[binding.destination[0]] = sb;
-                                IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                            }
-                        }
+
+                        prepareCreatedBinding(sb as IBinding, binding);
                     }
                     else if (fieldWatcher == null || fieldWatcher.eventNames == null)
                     {
-                        makeConstantBinding(binding, _strand);
+                        makeConstantBinding(binding);
                     }
                 }
                 else
@@ -188,34 +172,41 @@ package org.apache.flex.binding
             }
         }
 
-        private function makeConstantBinding(binding:Object,strand:IStrand):void{
-            var cb:ConstantBinding = new ConstantBinding();
-            cb.destinationPropertyName = binding.destination[1];
-            if (binding.source is String) {
-                cb.sourcePropertyName = binding.source;
-            } else {
-                cb.sourceID = binding.source[0];
-                cb.sourcePropertyName = binding.source[1];
-            }
-            cb.setDocument(strand);
-            var destObject:Object = strand[binding.destination[0]];
-            var destination:IStrand = destObject as IStrand;
+        private function prepareCreatedBinding(binding:IBinding, bindingObject:Object):void
+        {
+            var destinationObject:Object = _strand[bindingObject.destination[0]];
+            var destination:IStrand = destinationObject as IStrand;
             if (destination)
-                destination.addBead(cb);
+            {
+                destination.addBead(binding as IBead);
+            }
             else
             {
-                if (destObject)
+                if (destinationObject)
                 {
-                    cb.destination = destObject;
-                    strand.addBead(cb);
+                    binding.destination = destinationObject;
+                    _strand.addBead(binding as IBead);
                 }
                 else
                 {
-                    deferredBindings[binding.destination[0]] = cb;
-                    IEventDispatcher(strand).addEventListener("valueChange", deferredBindingsHandler);
+                    deferredBindings[bindingObject.destination[0]] = binding;
+                    IEventDispatcher(_strand).addEventListener("valueChange", deferredBindingsHandler);
                 }
             }
+        }
 
+        private function makeConstantBinding(binding:Object):void{
+            var cb:ConstantBinding = new ConstantBinding();
+            cb.destinationPropertyName = binding.destination[1];
+            if (binding.source is String) {
+                cb.sourcePropertyName = binding.source;
+            } else {
+                cb.sourceID = binding.source[0];
+                cb.sourcePropertyName = binding.source[1];
+            }
+            cb.setDocument(_strand);
+
+            prepareCreatedBinding(cb as IBinding, binding);
         }
 
         private function makeGenericBinding(binding:Object, index:int, watchers:Object):void
@@ -379,6 +370,5 @@ package org.apache.flex.binding
                 }
             }
         }
-        
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ac1bf7a6/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/MXMLBeadViewDataBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/MXMLBeadViewDataBinding.as
b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/MXMLBeadViewDataBinding.as
index 0579ace..9c78e4e 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/MXMLBeadViewDataBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/MXMLBeadViewDataBinding.as
@@ -22,6 +22,7 @@ package org.apache.flex.binding
     import org.apache.flex.binding.GenericBinding;
     import org.apache.flex.binding.PropertyWatcher;
     import org.apache.flex.binding.SimpleBinding;
+    import org.apache.flex.core.IBinding;
     import org.apache.flex.binding.WatcherBase;
     import org.apache.flex.core.DataBindingBase;
     import org.apache.flex.core.IBead;
@@ -75,18 +76,20 @@ package org.apache.flex.binding
 
         private function initCompleteHandler(event:Event):void
         {
-            var fieldWatcher:Object;
-            var sb:SimpleBinding;
             if (!("_bindings" in _strand))
                 return;
+
+            var fieldWatcher:Object;
+            var sb:SimpleBinding;
             var bindingData:Array = _strand["_bindings"];
             var n:int = bindingData[0];
             var bindings:Array = [];
+            var binding:Object = null;
             var i:int;
             var index:int = 1;
             for (i = 0; i < n; i++)
             {
-                var binding:Object = {};
+                binding = {};
                 binding.source = bindingData[index++];
 				binding.destFunc = bindingData[index++];
                 binding.destination = bindingData[index++];
@@ -95,19 +98,22 @@ package org.apache.flex.binding
             var watchers:Object = decodeWatcher(bindingData.slice(index));
             for (i = 0; i < n; i++)
             {
-                    binding = bindings[i];
+                binding = bindings[i];
                 if (binding.source is Array)
                 {
                     if (binding.source[0] in _strand)
                     {
                         if (binding.source.length == 2 && binding.destination.length
== 2)
                         {
-                            var destObject:Object;
-                            var destination:IStrand;
                             // can be simplebinding or constantbinding
-                            var modelWatcher:Object = watchers.watcherMap[binding.source[0]];
-                            fieldWatcher = modelWatcher.children.watcherMap[binding.source[1]];
-                            if (fieldWatcher.eventNames is String)
+                            var compWatcher:Object = watchers.watcherMap[binding.source[0]];
+
+                            if (compWatcher)
+                            {
+                                fieldWatcher = compWatcher.children.watcherMap[binding.source[1]];
+                            }
+
+                            if (fieldWatcher && fieldWatcher.eventNames is String)
                             {
                                 sb = new SimpleBinding();
                                 sb.destinationPropertyName = binding.destination[1];
@@ -115,48 +121,18 @@ package org.apache.flex.binding
                                 sb.sourceID = binding.source[0];
                                 sb.sourcePropertyName = binding.source[1];
                                 sb.setDocument(_strand);
-                                destObject = _strand[binding.destination[0]];           
                    
-                                destination = destObject as IStrand;
-                                if (destination)
-                                    destination.addBead(sb);
-                                else
-                                {
-                                    if (destObject)
-                                    {
-                                        sb.destination = destObject;
-                                        _strand.addBead(sb);
-                                    }
-                                    else
-                                    {
-                                        deferredBindings[binding.destination[0]] = sb;
-                                        IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                                    }
-                                }
+
+                                prepareCreatedBinding(sb as IBinding, binding);
                             }
-                            else if (fieldWatcher.eventNames == null)
+                            else if (fieldWatcher && fieldWatcher.eventNames == null)
                             {
                                 var cb:ConstantBinding = new ConstantBinding();
                                 cb.destinationPropertyName = binding.destination[1];
                                 cb.sourceID = binding.source[0];
                                 cb.sourcePropertyName = binding.source[1];
                                 cb.setDocument(_strand);
-                                destObject = _strand[binding.destination[0]];           
                    
-                                destination = destObject as IStrand;
-                                if (destination)
-                                    destination.addBead(cb);
-                                else
-                                {
-                                    if (destObject)
-                                    {
-                                        cb.destination = destObject;
-                                        _strand.addBead(cb);
-                                    }
-                                    else
-                                    {
-                                        deferredBindings[binding.destination[0]] = cb;
-                                        IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                                    }
-                                }
+
+                                prepareCreatedBinding(cb as IBinding, binding);
                             }
                         }
                     }
@@ -171,29 +147,39 @@ package org.apache.flex.binding
                         sb.eventName = fieldWatcher.eventNames as String;
                         sb.sourcePropertyName = binding.source;
                         sb.setDocument(_strand);
-                        destObject = _strand[binding.destination[0]];                   
            
-                        destination = destObject as IStrand;
-                        if (destination)
-                            destination.addBead(sb);
-                        else
-                        {
-                            if (destObject)
-                            {
-                                sb.destination = destObject;
-                                _strand.addBead(sb);
-                            }
-                            else
-                            {
-                                deferredBindings[binding.destination[0]] = sb;
-                                IEventDispatcher(_strand).addEventListener("valueChange",
deferredBindingsHandler);
-                            }
-                        }
+
+                        prepareCreatedBinding(sb as IBinding, binding);
                     }
                 }
                 else
                 {
                     makeGenericBinding(binding, i, watchers);
                 }
+
+                fieldWatcher = null;
+            }
+        }
+
+        private function prepareCreatedBinding(binding:IBinding, bindingObject:Object):void
+        {
+            var destinationObject:Object = _strand[bindingObject.destination[0]];
+            var destination:IStrand = destinationObject as IStrand;
+            if (destination)
+            {
+                destination.addBead(binding as IBead);
+            }
+            else
+            {
+                if (destinationObject)
+                {
+                    binding.destination = destinationObject;
+                    _strand.addBead(binding as IBead);
+                }
+                else
+                {
+                    deferredBindings[bindingObject.destination[0]] = binding;
+                    IEventDispatcher(_strand).addEventListener("valueChange", deferredBindingsHandler);
+                }
             }
         }
 


Mime
View raw message