flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [1/2] git commit: [flex-asjs] [refs/heads/develop] - Allow chained assignment to non-existent children
Date Mon, 28 Aug 2017 09:55:32 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 885e32136 -> 641f74c04


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/develop
Commit: 884826ebfb9184574a17e6cb0a9f62331a4a31be
Parents: 37dc600
Author: Harbs <harbs@in-tools.com>
Authored: Mon Aug 28 12:54:52 2017 +0300
Committer: Harbs <harbs@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>;


Mime
View raw message