Fix bug  FLEX-35239 - If in watchers map source of our data binding and event 
name do not exist make ConstantBinding
- If ConstantBinding during initialization won't find in "document" source - 
trying to create class from sourceID string


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

Branch: refs/heads/feature/fontawesome
Commit: b516503befd2b2e4a75a5c0cf9c3bd190c51093c
Parents: fa00540
Author: piotrz <[email protected]>
Authored: Sat Jan 7 00:55:12 2017 +0100
Committer: piotrz <[email protected]>
Committed: Sat Jan 7 00:55:12 2017 +0100

----------------------------------------------------------------------
 .../org/apache/flex/binding/ConstantBinding.as  | 82 ++++++++++++++++----
 .../flex/binding/ItemRendererDataBinding.as     | 49 ++++--------
 2 files changed, 86 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b516503b/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 70cb124..ac3d1d6 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,7 +21,11 @@ package org.apache.flex.binding
        import org.apache.flex.core.IBead;
        import org.apache.flex.core.IStrand;
        import org.apache.flex.core.IDocument;
-       
+
+    COMPILE::SWF
+    {
+        import flash.utils.getDefinitionByName;
+    }
     /**
      *  The ConstantBinding class is lightweight data-binding class that
      *  is optimized for simple assignments of one object's constant to
@@ -126,17 +130,53 @@ package org.apache.flex.binding
          */
                public function set strand(value:IStrand):void
                {
+            var val:* = null;
+            var objectFromWindow:Object = null;
+
             if (destination == null)
                 destination = value;
             
             if (sourceID != null)
-                       source = document[sourceID];
+            {
+                source = document[sourceID];
+            }
             else
+            {
                 source = document;
-            var val:*;
-            if (sourcePropertyName in source)
+            }
+
+            if (!source)
+            {
+                try
+                {
+                    COMPILE::SWF
+                    {
+                        var classFromSourceId:Class = 
getDefinitionByName(sourceID) as Class;
+                        if (classFromSourceId)
+                        {
+                            val = classFromSourceId[sourcePropertyName];
+                        }
+                    }
+
+                    COMPILE::JS
+                    {
+                        objectFromWindow = getObjectClassFromWindow(sourceID);
+                        if (objectFromWindow)
+                        {
+                            val = objectFromWindow[sourcePropertyName];
+                        }
+                    }
+                    destination[destinationPropertyName] = val;
+                }
+                catch (e:Error)
+                {
+
+                }
+            }
+            else if (sourcePropertyName in source)
             {
-                try {
+                try
+                {
                     val = source[sourcePropertyName];
                     destination[destinationPropertyName] = val;
                 }
@@ -146,7 +186,8 @@ package org.apache.flex.binding
             }
             else if (sourcePropertyName in source.constructor)
             {
-                try {
+                try
+                {
                     val = source.constructor[sourcePropertyName];
                     destination[destinationPropertyName] = val;
                 }
@@ -164,13 +205,11 @@ package org.apache.flex.binding
                     if (cname) 
                     {
                         cname = cname.names[0].qName;
-                        var parts:Array = cname.split('.');
-                        var n:int = parts.length;
-                        var o:Object = window;
-                        for (var i:int = 0; i < n; i++) {
-                            o = o[parts[i]];
+                        objectFromWindow = getObjectClassFromWindow(cname);
+                        if (objectFromWindow)
+                        {
+                            val = objectFromWindow[sourcePropertyName];
                         }
-                        val = o[sourcePropertyName];
                         destination[destinationPropertyName] = val;
                     }                    
                 }
@@ -190,6 +229,23 @@ package org.apache.flex.binding
                {
                        this.document = document;
                }
-               
+
+        COMPILE::JS
+        private function getObjectClassFromWindow(className:Object):Object
+        {
+            var windowObject:Object = window;
+            var parts:Array = className.split('.');
+            var n:int = parts.length;
+            if (n == 0)
+            {
+                return null;
+            }
+
+            for (var i:int = 0; i < n; i++) {
+                windowObject = windowObject[parts[i]];
+            }
+
+            return windowObject;
+        }
        }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b516503b/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 ac54206..315a372 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
@@ -72,7 +72,6 @@ package org.apache.flex.binding
             var fieldWatcher:Object;
             var isStatic:Boolean;
             var sb:SimpleBinding;
-            var cb:ConstantBinding;
             if (!("_bindings" in _strand))
                 return;
             var bindingData:Array = _strand["_bindings"];
@@ -92,8 +91,9 @@ package org.apache.flex.binding
             var watchers:Object = decodeWatcher(bindingData.slice(index));
             for (i = 0; i < n; i++)
             {
-                    binding = bindings[i];
+                binding = bindings[i];
                 var destination:IStrand;
+
                 if (binding.source is String)
                 {
                     fieldWatcher = watchers.watcherMap[binding.source];
@@ -130,12 +130,16 @@ package org.apache.flex.binding
                 else if (binding.source is Array
                         && binding.source.length == 2 && 
binding.destination.length == 2)
                 {
-                    var compWatcher:Object;
-                    compWatcher = watchers.watcherMap[binding.source[0]];
-                    fieldWatcher = 
compWatcher.children.watcherMap[binding.source[1]];
-                    if (binding.source[0] == "data" ||
-                            (compWatcher.eventNames is String
-                            && compWatcher.eventNames == "dataChange"))
+                    var compWatcher:Object = 
watchers.watcherMap[binding.source[0]];
+                    if (compWatcher)
+                    {
+                        fieldWatcher = 
compWatcher.children.watcherMap[binding.source[1]];
+                    }
+
+                    if (compWatcher && fieldWatcher &&
+                            (binding.source[0] == "data" ||
+                            (compWatcher.eventNames is String &&
+                            compWatcher.eventNames == "dataChange")))
                     {
                         var irsb:ItemRendererSimpleBinding = new 
ItemRendererSimpleBinding();
                         irsb.destinationID = binding.destination[0];
@@ -144,7 +148,7 @@ package org.apache.flex.binding
                         irsb.setDocument(_strand);
                         _strand.addBead(irsb);
                     }
-                    else if (fieldWatcher.eventNames is String)
+                    else if (fieldWatcher != null && fieldWatcher.eventNames 
is String)
                     {
                         sb = new SimpleBinding();
                         sb.destinationPropertyName = binding.destination[1];
@@ -170,36 +174,17 @@ package org.apache.flex.binding
                             }
                         }
                     }
-                    else if (fieldWatcher.eventNames == null)
+                    else if (fieldWatcher == null || fieldWatcher.eventNames 
== null)
                     {
-                        cb = 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);
-                            }
-                        }
+                        makeConstantBinding(binding, _strand);
                     }
                 }
                 else
                 {
                     makeGenericBinding(binding, i, watchers);
                 }
+
+                fieldWatcher = null;
             }
         }
 

Reply via email to