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] - FLEX-35227, FLEX-35236 - Remove from ViewDataBinding condition (binding source as an applicationModel) which do not allow create SimpleDataBinding - Improve readability of ViewDataBiding - Intorduce IBinding
Date Tue, 10 Jan 2017 23:05:19 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop e802c11f4 -> 2ca8651d9


FLEX-35227, FLEX-35236
- Remove from ViewDataBinding condition (binding source as an applicationModel) which do not
allow create SimpleDataBinding
- Improve readability of ViewDataBiding
- Intorduce IBinding interface with common properties related to ConstantBinding and SimpleBinding


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

Branch: refs/heads/develop
Commit: 2ca8651d9afae09aedd855d18f038afaa1374aae
Parents: e802c11
Author: piotrz <piotrz@apache.org>
Authored: Wed Jan 11 00:05:14 2017 +0100
Committer: piotrz <piotrz@apache.org>
Committed: Wed Jan 11 00:05:14 2017 +0100

----------------------------------------------------------------------
 .../org/apache/flex/binding/ConstantBinding.as  |  67 +++++++---
 .../org/apache/flex/binding/PropertyWatcher.as  |   2 +
 .../org/apache/flex/binding/SimpleBinding.as    | 124 +++++++++++--------
 .../org/apache/flex/binding/ViewDataBinding.as  | 111 +++++++----------
 .../projects/Core/src/main/flex/CoreClasses.as  |   1 +
 .../main/flex/org/apache/flex/core/IBinding.as  |  82 ++++++++++++
 6 files changed, 253 insertions(+), 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2ca8651d/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ConstantBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ConstantBinding.as
b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ConstantBinding.as
index ac3d1d6..7d3749e 100644
--- a/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ConstantBinding.as
+++ b/frameworks/projects/Binding/src/main/flex/org/apache/flex/binding/ConstantBinding.as
@@ -21,6 +21,7 @@ package org.apache.flex.binding
 	import org.apache.flex.core.IBead;
 	import org.apache.flex.core.IStrand;
 	import org.apache.flex.core.IDocument;
+    import org.apache.flex.core.IBinding;
 
     COMPILE::SWF
     {
@@ -36,7 +37,7 @@ package org.apache.flex.binding
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public class ConstantBinding implements IBead, IDocument
+	public class ConstantBinding implements IBead, IDocument, IBinding
 	{
         /**
          *  Constructor.
@@ -49,7 +50,12 @@ package org.apache.flex.binding
 		public function ConstantBinding()
 		{
 		}
-		
+
+        private var _destination:Object;
+        private var _sourceID:String;
+        private var _destinationPropertyName:String;
+        private var _sourcePropertyName:String;
+
         /**
          *  The source object who's property has the value we want.
          *
@@ -76,50 +82,77 @@ package org.apache.flex.binding
 		protected var document:Object;
 
         /**
-         *  The destination object.  It is always the same
-         *  as the strand.  ConstantBindings are attached to
-         *  the strand of the destination object.
+         *  @copy org.apache.flex.core.IBinding#destination;
          *
          *  @langversion 3.0
          *  @playerversion Flash 10.2
          *  @playerversion AIR 2.6
          *  @productversion FlexJS 0.0
          */
-        public var destination:Object;
+        public function get destination():Object
+        {
+            return _destination;
+        }
+
+        public function set destination(value:Object):void
+        {
+            _destination = value;
+        }
 
         /**
-         *  If not null, the id of the mxml tag who's property
-         *  is being watched for changes.
+         *  @copy org.apache.flex.core.IBinding#sourceID
          *
          *  @langversion 3.0
          *  @playerversion Flash 10.2
          *  @playerversion AIR 2.6
          *  @productversion FlexJS 0.0
          */
-        public var sourceID:String;
+        public function get sourceID():String
+        {
+            return _sourceID;
+        }
+
+        public function set sourceID(value:String):void
+        {
+            _sourceID = value;
+        }
 
         /**
-         *  If not null, the name of a property on the
-         *  mxml document that is being watched for changes.
+         *  @copy org.apache.flex.core.IBinding#destinationPropertyName
          *
          *  @langversion 3.0
          *  @playerversion Flash 10.2
          *  @playerversion AIR 2.6
          *  @productversion FlexJS 0.0
          */
-        public var sourcePropertyName:String;
+        public function get destinationPropertyName():String
+        {
+            return _destinationPropertyName;
+        }
+
+        public function set destinationPropertyName(value:String):void
+        {
+            _destinationPropertyName = value;
+        }
 
         /**
-         *  The name of the property on the strand that
-         *  is set when the source property changes.
+         *  @copy org.apache.flex.core.IBinding#sourcePropertyName
          *
          *  @langversion 3.0
          *  @playerversion Flash 10.2
          *  @playerversion AIR 2.6
          *  @productversion FlexJS 0.0
          */
-        public var destinationPropertyName:String;
-		
+        public function get sourcePropertyName():String
+        {
+            return _sourcePropertyName;
+        }
+
+        public function set sourcePropertyName(value:String):void
+        {
+            _sourcePropertyName = value;
+        }
+
         /**
          *  @copy org.apache.flex.core.IBead#strand
          *
@@ -247,5 +280,5 @@ package org.apache.flex.binding
 
             return windowObject;
         }
-	}
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2ca8651d/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 1ea83ef..d6e7fef 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
@@ -185,7 +185,9 @@ package org.apache.flex.binding
         private function addEventListeners():void
         {
             if (eventNames is String)
+            {
                 dispatcher.addEventListener(eventNames as String, changeHandler);
+            }
             else if (eventNames is Array)
             {
                 var arr:Array = eventNames as Array;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2ca8651d/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 1fef25f..4c99a52 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
@@ -24,7 +24,7 @@ import org.apache.flex.core.IDocument;
 import org.apache.flex.events.IEventDispatcher;
 import org.apache.flex.events.Event;
 import org.apache.flex.events.ValueChangeEvent;
-
+import org.apache.flex.core.IBinding;
 /**
  *  The SimpleBinding class is lightweight data-binding class that
  *  is optimized for simple assignments of one object's property to
@@ -35,7 +35,7 @@ import org.apache.flex.events.ValueChangeEvent;
  *  @playerversion AIR 2.6
  *  @productversion FlexJS 0.0
  */
-public class SimpleBinding implements IBead, IDocument
+public class SimpleBinding implements IBead, IDocument, IBinding
 {
 	/**
 	 *  Constructor.
@@ -51,6 +51,10 @@ public class SimpleBinding implements IBead, IDocument
 	}
 
 	private var _isStatic:Boolean;
+    private var _destination:Object;
+    private var _sourceID:String;
+    private var _destinationPropertyName:String;
+    private var _sourcePropertyName:String;
 
 	/**
 	 *  The event dispatcher that dispatches an event
@@ -64,9 +68,7 @@ public class SimpleBinding implements IBead, IDocument
 	 */
 	protected var dispatcher:IEventDispatcher;
 
-
 	/**
-
 	 *  The source object that dispatches an event
 	 *  when the property changes
 	 *
@@ -94,41 +96,6 @@ public class SimpleBinding implements IBead, IDocument
 	 */
 	protected var document:Object;
 
-
-	/**
-	 *  The destination object.  It is always the same
-	 *  as the strand.  SimpleBindings are attached to
-	 *  the strand of the destination object.
-	 *
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.0
-	 */
-	public var destination:Object;
-
-	/**
-	 *  If not null, the id of the mxml tag who's property
-	 *  is being watched for changes.
-	 *
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.0
-	 */
-	public var sourceID:String;
-
-	/**
-	 *  If not null, the name of a property on the
-	 *  mxml document that is being watched for changes.
-	 *
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.0
-	 */
-	public var sourcePropertyName:String;
-
 	/**
 	 *  The event name that is dispatched when the source
 	 *  property changes.
@@ -140,18 +107,77 @@ public class SimpleBinding implements IBead, IDocument
 	 */
 	public var eventName:String;
 
-	/**
-	 *  The name of the property on the strand that
-	 *  is set when the source property changes.
-	 *
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.0
-	 */
-	public var destinationPropertyName:String;
+    /**
+     *  @copy org.apache.flex.core.IBinding#destination;
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function get destination():Object
+    {
+        return _destination;
+    }
+
+    public function set destination(value:Object):void
+    {
+        _destination = value;
+    }
+
+    /**
+     *  @copy org.apache.flex.core.IBinding#sourceID
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function get sourceID():String
+    {
+        return _sourceID;
+    }
+
+    public function set sourceID(value:String):void
+    {
+        _sourceID = value;
+    }
+
+    /**
+     *  @copy org.apache.flex.core.IBinding#destinationPropertyName
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function get destinationPropertyName():String
+    {
+        return _destinationPropertyName;
+    }
+
+    public function set destinationPropertyName(value:String):void
+    {
+        _destinationPropertyName = value;
+    }
 
+    /**
+     *  @copy org.apache.flex.core.IBinding#sourcePropertyName
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function get sourcePropertyName():String
+    {
+        return _sourcePropertyName;
+    }
 
+    public function set sourcePropertyName(value:String):void
+    {
+        _sourcePropertyName = value;
+    }
 
 	/**
 	 *  @copy org.apache.flex.core.IBead#strand

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2ca8651d/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 44c5489..ccead68 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
@@ -23,6 +23,7 @@ package org.apache.flex.binding
     import org.apache.flex.binding.PropertyWatcher;
     import org.apache.flex.binding.SimpleBinding;
     import org.apache.flex.binding.WatcherBase;
+    import org.apache.flex.core.IBinding;
     import org.apache.flex.core.IBead;
     import org.apache.flex.core.IStrand;
     import org.apache.flex.events.Event;
@@ -80,7 +81,6 @@ package org.apache.flex.binding
             if (!("_bindings" in _strand))
                 return;
             var bindingData:Array = _strand["_bindings"];
-            var destObject:Object;
             var n:int = bindingData[0];
             var bindings:Array = [];
             var i:int;
@@ -101,7 +101,10 @@ package org.apache.flex.binding
                 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";
@@ -110,36 +113,29 @@ package org.apache.flex.binding
                         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, binding);
                     }
                 }
                 else
                 if (binding.source is Array
-                        && binding.source[0] == "applicationModel"
-                        && binding.source.length == 2 && binding.destination.length
== 2)
+                    && binding.source.length == 2 && binding.destination.length
== 2)
                 {
                     // can be simplebinding or constantbinding
-                    var modelWatcher:Object = watchers.watcherMap["applicationModel"];
-                    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];
@@ -147,58 +143,30 @@ 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);
                     }
                 }
                 else
                 {
                     makeGenericBinding(binding, i, watchers);
                 }
+
+                fieldWatcher = null;
             }
         }
 
-        private function makeConstantBinding(binding:Object,strand:IStrand):void{
+        private function makeConstantBinding(binding:Object):void{
             var cb:ConstantBinding = new ConstantBinding();
             cb.destinationPropertyName = binding.destination[1];
             if (binding.source is String) {
@@ -207,25 +175,32 @@ package org.apache.flex.binding
                 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;
+            cb.setDocument(_strand);
+
+            prepareCreatedBinding(cb as IBinding, binding);
+        }
+
+        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 makeGenericBinding(binding:Object, index:int, watchers:Object):void

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2ca8651d/frameworks/projects/Core/src/main/flex/CoreClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as
index a8cc08d..5754cbc 100644
--- a/frameworks/projects/Core/src/main/flex/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as
@@ -51,6 +51,7 @@ internal class CoreClasses
 	import org.apache.flex.core.IBeadTransform; IBeadTransform;
     import org.apache.flex.core.IBeadModel; IBeadModel;
 	import org.apache.flex.core.IBeadView; IBeadView;
+	import org.apache.flex.core.IBinding; IBinding;
 	import org.apache.flex.core.IImageView; IImageView;
     import org.apache.flex.core.IBinaryImage; IBinaryImage;
 	COMPILE::SWF

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2ca8651d/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinding.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinding.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinding.as
new file mode 100644
index 0000000..4054fc6
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinding.as
@@ -0,0 +1,82 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.core
+{
+	/**
+	 *  IBinding interface is a "marker" for data-binding class that
+	 *  is optimized for simple assignments of one object's property to
+	 *  another object's property.
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */
+	public interface IBinding
+	{
+		/**
+		 *  The destination object.  It is always the same
+		 *  as the strand.  SimpleBindings are attached to
+		 *  the strand of the destination object.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+        function get destination():Object;
+        function set destination(value:Object):void;
+
+		/**
+		 *  If not null, the id of the mxml tag who's property
+		 *  is being watched for changes.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		 function get sourceID():String;
+		 function set sourceID(value:String):void;
+
+		/**
+		 *  If not null, the name of a property on the
+		 *  mxml document that is being watched for changes.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		 function get sourcePropertyName():String;
+		 function set sourcePropertyName(value:String):void;
+
+		/**
+		 *  The name of the property on the strand that
+		 *  is set when the source property changes.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		 function get destinationPropertyName():String;
+		 function set destinationPropertyName(value:String):void;
+    }
+}


Mime
View raw message