You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2017/08/30 20:37:42 UTC

[30/32] git commit: [flex-asjs] [refs/heads/feature/dragAndDrop] - Allow chained assignment to non-existent children

Allow chained assignment to non-existent children


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

Branch: refs/heads/feature/dragAndDrop
Commit: 884826ebfb9184574a17e6cb0a9f62331a4a31be
Parents: 37dc600
Author: Harbs <ha...@in-tools.com>
Authored: Mon Aug 28 12:54:52 2017 +0300
Committer: Harbs <ha...@in-tools.com>
Committed: Mon Aug 28 12:54:52 2017 +0300

----------------------------------------------------------------------
 frameworks/projects/XML/src/main/flex/XML.as    | 10 +++++++
 .../projects/XML/src/main/flex/XMLList.as       | 31 ++++++++++++++++----
 manualtests/XMLTest/src/MyInitialView.mxml      |  5 ++++
 3 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/884826eb/frameworks/projects/XML/src/main/flex/XML.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/XML.as b/frameworks/projects/XML/src/main/flex/XML.as
index cf3d9ea..7e749fc 100644
--- a/frameworks/projects/XML/src/main/flex/XML.as
+++ b/frameworks/projects/XML/src/main/flex/XML.as
@@ -2131,6 +2131,16 @@ package
 		{
 			_value = value;
 		}
+
+		/**
+		 * @private
+		 * 
+		 * Allows XMLList to get the targetObject of its targetObject and not error when it gets the XML
+		 */
+		public function get targetObject():*
+		{
+			return null;
+		}
 		
 		/**
 		 * Returns an XMLList object of all XML properties of the XML object that represent XML text nodes.

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/884826eb/frameworks/projects/XML/src/main/flex/XMLList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/XMLList.as b/frameworks/projects/XML/src/main/flex/XMLList.as
index d90ee3d..6f8dcdd 100644
--- a/frameworks/projects/XML/src/main/flex/XMLList.as
+++ b/frameworks/projects/XML/src/main/flex/XMLList.as
@@ -230,6 +230,7 @@ package
 		public function child(propertyName:Object):XMLList
 		{
 			var retVal:XMLList = new XMLList();
+			retVal.targetProperty = propertyName.toString();
 			var propNum:Number = parseInt(propertyName,10);
 			if(propNum.toString() == propertyName)
 			{
@@ -240,9 +241,12 @@ package
 				}
 				return retVal;
 			}
+			if(isEmpty())
+			{
+				retVal.targetObject = this;
+			}
 			if(isSingle())
 				return _xmlArray[0].child(propertyName);
-			
 			var len:int = _xmlArray.length;
 			for (var i:int=0;i<len;i++)
 			{
@@ -783,12 +787,25 @@ package
 		{
 			return _targetProperty;
 		}
-		
-		public function setAttribute(attr:*,value:String):void
+		private function xmlFromProperty():XML
 		{
+			var xmlStr:String = "<";
+			if(_targetProperty.prefix)
+				xmlStr += _targetProperty.prefix + "::";
+
+			xmlStr += _targetProperty.localName + "/>";
+			return new XML(xmlStr);
+		}
+		public function setAttribute(attr:*,value:String):String
+		{
+			if(isEmpty() && targetObject)//walk up the tree and create nodes.
+				_xmlArray[0] = targetObject.setChild(_targetProperty,xmlFromProperty());
+
 			var len:int = _xmlArray.length;
 			for (var i:int=0;i<len;i++)
 				_xmlArray[i].setAttribute(attr,value);
+			
+			return value;
 
 		}
 		public function hasAncestor(obj:*):Boolean
@@ -840,11 +857,15 @@ package
 			if(isSingle())
 				return _xmlArray[0].replace(propertyName,value);
 		}
-		public function setChild(elementName:*, elements:Object):void
+		public function setChild(elementName:*, elements:Object):Object
 		{
+			if(isEmpty() && targetObject)//walk up the tree and create nodes.
+				_xmlArray[0] = targetObject.setChild(_targetProperty,xmlFromProperty());
+
 			if(isSingle())
 				_xmlArray[0].setChild(elementName,elements);
-
+			
+			return elements;
 		}
 
 		public function setParent(parent:XML):void

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/884826eb/manualtests/XMLTest/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/manualtests/XMLTest/src/MyInitialView.mxml b/manualtests/XMLTest/src/MyInitialView.mxml
index 6b73d7f..851aeac 100644
--- a/manualtests/XMLTest/src/MyInitialView.mxml
+++ b/manualtests/XMLTest/src/MyInitialView.mxml
@@ -103,6 +103,11 @@ limitations under the License.
         trace(xml1.toXMLString() == '<foo baz="true"/>');
         var baz:XMLList = xml1.@baz;
         trace("baz: " + xml1.@baz.toString() + " //true");
+				var xml3:XML = <root/>;
+				xml3.bar.baz = "baz";
+				xml3.foo.@boo = "boo";
+				trace("baz? " + xml3.bar.baz);
+				trace("boo? " + xml3.foo.@boo);
         var child:XML = <pop><child name="Sam"/></pop>;
         xml1.appendChild(child);
         child = <pop><child name="George"/></pop>;