You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2016/08/30 07:30:44 UTC

[03/11] git commit: [flex-asjs] [refs/heads/develop] - [IMPROVEMENTS] Cumulative improvements across binding framework classes: - Support in some classes added for static bindings - removed n-2 check in _bindings loop because the extra null appended to t

[IMPROVEMENTS] Cumulative improvements across binding framework classes:
- Support in some classes added for static bindings
- removed n-2 check in _bindings loop because the extra null appended to the _bindings array by falcon-jx has now gone
- when a child watcher is not found (e.g. last part of binding chain is not bindable, update the value. This might need more attention


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

Branch: refs/heads/develop
Commit: 95af7f023d7dc5130d9d7bb50041ca50fbcf3865
Parents: 2c21ebc
Author: greg-dove <gr...@gmail.com>
Authored: Mon Aug 29 12:13:14 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Mon Aug 29 12:13:14 2016 +1200

----------------------------------------------------------------------
 .../flex/binding/ApplicationDataBinding.as      |   5 +-
 .../apache/flex/binding/ContainerDataBinding.as |   5 +-
 .../org/apache/flex/binding/GenericBinding.as   |  27 ++-
 .../flex/binding/MXMLBeadViewDataBinding.as     |   5 +-
 .../org/apache/flex/binding/PropertyWatcher.as  |   9 +-
 .../org/apache/flex/binding/SimpleBinding.as    |  41 ++---
 .../org/apache/flex/binding/ViewDataBinding.as  | 164 +++++++++++--------
 7 files changed, 150 insertions(+), 106 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/95af7f02/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 2974ea5..94da494 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
@@ -270,10 +270,7 @@ package org.apache.flex.binding
             var n:int = bindingData.length;
             var index:int = 0;
             var watcherData:Object;
-            // FalconJX adds an extra null to the data so make sure
-            // we have enough data for a complete watcher otherwise
-            // say we are done
-            while (index < n - 2)
+            while (index < n - 1)
             {
                 var watcherIndex:int = bindingData[index++];
                 var type:int = bindingData[index++];

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/95af7f02/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 751f235..156aa69 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
@@ -316,10 +316,7 @@ package org.apache.flex.binding
             var n:int = bindingData.length;
             var index:int = 0;
             var watcherData:Object;
-            // FalconJX adds an extra null to the data so make sure
-            // we have enough data for a complete watcher otherwise
-            // say we are done
-            while (index < n - 2)
+            while (index < n - 1)
             {
                 var watcherIndex:int = bindingData[index++];
                 var type:int = bindingData[index++];

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/95af7f02/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/GenericBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/GenericBinding.as b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/GenericBinding.as
index 72a2b4b..6ad75c8 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/GenericBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/GenericBinding.as
@@ -46,7 +46,8 @@ package org.apache.flex.binding
 		public function GenericBinding()
 		{
 		}
-		
+
+
         /**
          *  The mxml document for the
          *  binding expression.  If you bind to
@@ -107,6 +108,20 @@ package org.apache.flex.binding
          *  @productversion FlexJS 0.0
          */
         public var destinationFunction:Function;
+
+
+        /**
+         *  Flag used to indicate that the document
+         *  value refers to a Class with a static
+         *  bindable source
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public var isStatic:Boolean;
+        public var staticRoot:Object
 		
         /**
          *  @copy org.apache.flex.core.IBead#strand
@@ -135,7 +150,13 @@ package org.apache.flex.binding
             {
                 var arr:Array = source as Array;
                 var n:int = arr.length;
-                var obj:Object = document[arr[0]];
+                var obj:Object;
+                if (isStatic) {
+                    //ignore first element in the array, it is text representation of
+                    //staticRoot which here refers to the class
+                    obj=staticRoot;
+                } else obj = document[arr[0]];
+
                 if (obj == null)
                     return null;
                 for (var i:int = 1; i < n; i++)
@@ -154,7 +175,7 @@ package org.apache.flex.binding
             }
             else if (source is String)
             {
-                obj = document[source];
+                obj = isStatic ? staticRoot[source] : document[source];
                 return obj;
             }
             return null;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/95af7f02/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 7ec1dac..54168d5 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
@@ -265,10 +265,7 @@ package org.apache.flex.binding
             var n:int = bindingData.length;
             var index:int = 0;
             var watcherData:Object;
-            // FalconJX adds an extra null to the data so make sure
-            // we have enough data for a complete watcher otherwise
-            // say we are done
-            while (index < n - 2)
+            while (index < n - 1)
             {
                 var watcherIndex:int = bindingData[index++];
                 var type:int = bindingData[index++];

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/95af7f02/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/PropertyWatcher.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/PropertyWatcher.as b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/PropertyWatcher.as
index 7da6c5b..98015dc 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/PropertyWatcher.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/PropertyWatcher.as
@@ -37,7 +37,7 @@ package org.apache.flex.binding
          *  Constructor.
          *  
          *  @param source The object who's property we are watching.
-         *  @param proeprtyName The name of the property we are watching.
+         *  @param propertyName The name of the property we are watching.
          *  @param eventNames The name or array of names of events that get
          *  dispatched when the property changes.
          *  @param getterFunction  A function to call to get the value
@@ -52,7 +52,6 @@ package org.apache.flex.binding
                                             getterFunction:Function)
 		{
             this.source = source;
-            this.dispatcher = source;
             this.propertyName = propertyName;
             this.getterFunction = getterFunction;
             this.eventNames = eventNames;
@@ -69,7 +68,7 @@ package org.apache.flex.binding
          *  @playerversion AIR 2.6
          *  @productversion FlexJS 0.0
          */
-        protected var dispatcher:Object;
+        protected var dispatcher:IEventDispatcher;
 		
         /**
          *  The object who's property we are watching.
@@ -152,7 +151,7 @@ package org.apache.flex.binding
          */                
         override public function parentChanged(parent:Object):void
         {
-            if (dispatcher && dispatcher is IEventDispatcher)
+            if (dispatcher)
                 removeEventListeners();
 
             if (parent is PropertyWatcher)
@@ -161,7 +160,7 @@ package org.apache.flex.binding
                 source = parent;
             
             if (source) {
-                if (source is IEventDispatcher) dispatcher = source;
+                if (source is IEventDispatcher) dispatcher = IEventDispatcher(source);
                 else if (source is Class && source['staticEventDispatcher']!=null) dispatcher = source.staticEventDispatcher;
             }
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/95af7f02/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/SimpleBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/SimpleBinding.as b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/SimpleBinding.as
index 1d8bdfc..1fef25f 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/SimpleBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/SimpleBinding.as
@@ -45,10 +45,13 @@ public class SimpleBinding implements IBead, IDocument
 	 *  @playerversion AIR 2.6
 	 *  @productversion FlexJS 0.0
 	 */
-	public function SimpleBinding()
+	public function SimpleBinding(isStatic:Boolean=false)
 	{
+		_isStatic = isStatic;
 	}
 
+	private var _isStatic:Boolean;
+
 	/**
 	 *  The event dispatcher that dispatches an event
 	 *  when the source property changes. This can
@@ -81,6 +84,8 @@ public class SimpleBinding implements IBead, IDocument
 	 *  like {foo} where foo is a property on
 	 *  the mxml documnet, or found as document[sourceID]
 	 *  for simple bindings like {someid.someproperty}
+	 *  It may be the document class for local static
+	 *  bindables (e.g. from a script block)
 	 *
 	 *  @langversion 3.0
 	 *  @playerversion Flash 10.2
@@ -161,28 +166,24 @@ public class SimpleBinding implements IBead, IDocument
 		if (dispatcher) dispatcher.removeEventListener(eventName, changeHandler);
 		if (destination == null)
 			destination = value;
-		if (sourceID != null)
-		{
-			source = dispatcher = document[sourceID] as IEventDispatcher;
-			if (source == null)
+		if (_isStatic) {
+			source = document;
+			dispatcher = source.staticEventDispatcher as IEventDispatcher;
+		} else {
+			if (sourceID != null)
 			{
-				document.addEventListener("valueChange",
-						sourceChangeHandler);
-				return;
-			}
-		}
-		else {
-			if (sourcePropertyName in document)
-			{
-				source = dispatcher = document as IEventDispatcher;
-			}
-			else if (sourcePropertyName in document.constructor)
-			{
-				source = document.constructor;
-				dispatcher = source.staticEventDispatcher as IEventDispatcher;
-			}
+				source = dispatcher = document[sourceID] as IEventDispatcher;
+				if (source == null)
+				{
+					document.addEventListener("valueChange",
+							sourceChangeHandler);
+					return;
+				}
+			} else
+			source = dispatcher = document as IEventDispatcher;
 		}
 
+
 		dispatcher.addEventListener(eventName, changeHandler);
 		try
 		{

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/95af7f02/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ViewDataBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ViewDataBinding.as b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ViewDataBinding.as
index 55a39bd..0612b1d 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ViewDataBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ViewDataBinding.as
@@ -75,6 +75,7 @@ package org.apache.flex.binding
         private function initCompleteHandler(event:Event):void
         {
             var fieldWatcher:Object;
+            var isStatic:Boolean;
             var sb:SimpleBinding;
             if (!("_bindings" in _strand))
                 return;
@@ -96,81 +97,57 @@ package org.apache.flex.binding
             for (i = 0; i < n; i++)
             {
                     binding = bindings[i];
-                if (binding.source is Array)
+                var destination:IStrand;
+                if (binding.source is String)
                 {
-                    if (binding.source[0] == "applicationModel")
+                    fieldWatcher = watchers.watcherMap[binding.source];
+                    if (!fieldWatcher) makeConstantBinding(binding, _strand);
+                    else if (fieldWatcher.eventNames is String)
                     {
-                        if (binding.source.length == 2 && binding.destination.length == 2)
+                        isStatic = 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
                         {
-                            var destination:IStrand;
-                            // can be simplebinding or constantbinding
-                            var modelWatcher:Object = watchers.watcherMap["applicationModel"];
-                            fieldWatcher = modelWatcher.children.watcherMap[binding.source[1]];
-                            if (fieldWatcher.eventNames is String)
+                            if (destObject)
                             {
-                                sb = new SimpleBinding();
-                                sb.destinationPropertyName = binding.destination[1];
-                                sb.eventName = fieldWatcher.eventNames as String;
-                                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);
-                                    }
-                                }
+                                sb.destination = destObject;
+                                _strand.addBead(sb);
                             }
-                            else if (fieldWatcher.eventNames == null)
+                            else
                             {
-                                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);
-                                    }
-                                }
+                                deferredBindings[binding.destination[0]] = sb;
+                                IEventDispatcher(_strand).addEventListener("valueChange", deferredBindingsHandler);
                             }
                         }
                     }
                 }
-                else if (binding.source is String)
+                else
+                if (binding.source is Array
+                        && binding.source[0] == "applicationModel"
+                        && binding.source.length == 2 && binding.destination.length == 2)
                 {
-                    fieldWatcher = watchers.watcherMap[binding.source];
+                    // can be simplebinding or constantbinding
+                    var modelWatcher:Object = watchers.watcherMap["applicationModel"];
+                    fieldWatcher = modelWatcher.children.watcherMap[binding.source[1]];
                     if (fieldWatcher.eventNames is String)
                     {
                         sb = new SimpleBinding();
                         sb.destinationPropertyName = binding.destination[1];
                         sb.eventName = fieldWatcher.eventNames as String;
-                        sb.sourcePropertyName = binding.source;
+                        sb.sourceID = binding.source[0];
+                        sb.sourcePropertyName = binding.source[1];
                         sb.setDocument(_strand);
-                        destObject = _strand[binding.destination[0]];                                
+                        destObject = _strand[binding.destination[0]];
                         destination = destObject as IStrand;
                         if (destination)
                             destination.addBead(sb);
@@ -188,6 +165,31 @@ package org.apache.flex.binding
                             }
                         }
                     }
+                    else if (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);
+                            }
+                        }
+                    }
                 }
                 else
                 {
@@ -196,6 +198,36 @@ 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;
+            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);
+                }
+            }
+
+        }
+
         private function makeGenericBinding(binding:Object, index:int, watchers:Object):void
         {
             var gb:GenericBinding = new GenericBinding();
@@ -227,6 +259,8 @@ package org.apache.flex.binding
                     {
 						case "static":
                             parentObj = watcher.parentObj;
+                            gb.staticRoot = parentObj;
+                            gb.isStatic = true;
                         case "property":
                         {
                             var pw:PropertyWatcher = new PropertyWatcher(this, 
@@ -253,11 +287,12 @@ package org.apache.flex.binding
                     }
                 }
             }
-            if (!foundWatcher && parentWatcher == null)
-            {
+            if (!foundWatcher )            {
                 // might be a binding to a function that doesn't have change events
-                // so just force an update
-                gb.valueChanged(null);
+                // so just force an update via parentWatcher (if it is set, null if not)
+                if (parentWatcher) gb.valueChanged(parentWatcher.value);
+                else gb.valueChanged(null);
+
             }
         }
         
@@ -268,10 +303,7 @@ package org.apache.flex.binding
             var n:int = bindingData.length;
             var index:int = 0;
             var watcherData:Object;
-            // FalconJX adds an extra null to the data so make sure
-            // we have enough data for a complete watcher otherwise
-            // say we are done
-            while (index < n - 2)
+            while (index < n - 1)
             {
                 var watcherIndex:int = bindingData[index++];
                 var type:int = bindingData[index++];