flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [14/15] git commit: [flex-asjs] [refs/heads/spark] - Initial Proxy implementation for FlexJS
Date Wed, 24 Feb 2016 05:44:55 GMT
Initial Proxy implementation for FlexJS


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

Branch: refs/heads/spark
Commit: 390a1d878f3369195e3b9d75f6bda785db4af2d3
Parents: 954154a
Author: Alex Harui <aharui@apache.org>
Authored: Sun Feb 21 22:03:43 2016 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Feb 23 21:44:22 2016 -0800

----------------------------------------------------------------------
 .../projects/Core/src/main/flex/CoreClasses.as  |   2 +
 .../main/flex/org/apache/flex/utils/Proxy.as    | 152 +++++++++++++++++++
 manualtests/ProxyTest/build.xml                 |  72 +++++++++
 manualtests/ProxyTest/src/MyInitialView.mxml    |  67 ++++++++
 manualtests/ProxyTest/src/ProxyTest.mxml        |  40 +++++
 manualtests/ProxyTest/src/README.txt            |  45 ++++++
 .../ProxyTest/src/controllers/MyController.as   |  52 +++++++
 manualtests/ProxyTest/src/models/MyModel.as     | 125 +++++++++++++++
 8 files changed, 555 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/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 ee984aa..5ad1688 100644
--- a/frameworks/projects/Core/src/main/flex/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as
@@ -140,6 +140,8 @@ internal class CoreClasses
     import org.apache.flex.core.ParentDocumentBead; ParentDocumentBead;
     import org.apache.flex.utils.CSSUtils; CSSUtils;
 
+    import org.apache.flex.utils.Proxy; Proxy;
+
 	COMPILE::JS
 	{
 	    import org.apache.flex.utils.Language; Language;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Proxy.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Proxy.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Proxy.as
new file mode 100644
index 0000000..39b6945
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Proxy.as
@@ -0,0 +1,152 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.utils
+{
+COMPILE::AS3
+{
+    import flash.utils.Proxy;
+	import flash.utils.flash_proxy;
+}
+
+COMPILE::JS
+{
+    import org.apache.flex.events.EventDispatcher;
+}
+
+//--------------------------------------
+//  Events
+//--------------------------------------
+
+/**
+ *  The Proxy class calls methods when properties
+ *  are set and read and deleted.  
+ *  
+ *  @langversion 3.0
+ *  @playerversion Flash 10.2
+ *  @playerversion AIR 2.6
+ *  @productversion FlexJS 0.0
+ */
+COMPILE::AS3
+public dynamic class Proxy extends flash.utils.Proxy
+{
+	private var valueMap:Object = {};
+	
+	override flash_proxy function getProperty(propName:*):*
+	{
+		return valueMap[propName];
+	}
+	
+	override flash_proxy function setProperty(propName:*, value:*):void
+	{
+		valueMap[propName] = value;
+	}
+	
+	override flash_proxy function hasProperty(propName:*):Boolean
+	{
+		return valueMap.hasOwnProperty(propName);
+	}
+	
+	override flash_proxy function deleteProperty(propName:*):Boolean
+	{
+		return delete valueMap[propName];
+	}
+	
+	private var names:Array;
+	
+	override flash_proxy function nextNameIndex (index:int):int 
+	{
+		// initial call
+		if (index == 0) {
+			names = new Array();
+			for (var p:* in valueMap) {
+				names.push(p);
+			}
+		}
+		
+		if (index < names.length) {
+			return index + 1;
+		} else {
+			return 0;
+		}
+	}
+	
+	override flash_proxy function nextName(index:int):String 
+	{
+		return names[index - 1];
+	}
+	
+	override flash_proxy function nextValue(index:int):* 
+	{
+		return valueMap[names[index - 1]];
+	}
+}
+
+COMPILE::JS
+public dynamic class Proxy extends EventDispatcher
+{
+    /**
+     *  Constructor.
+     * 
+     *  @param delay The number of milliseconds 
+     *  to wait before dispatching the event.
+     *  @param repeatCount The number of times to dispatch
+     *  the event.  If 0, keep dispatching forever.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function Proxy()
+    {
+    }
+    
+    
+	private var valueMap:Object = {};
+    
+    public function getProperty(propName:String):*
+    {
+        return valueMap[propName];
+    }
+    
+    public function setProperty(propName:String, value:*):void
+    {
+        valueMap[propName] = value;
+    }
+    
+    public function hasProperty(propName:String):Boolean
+    {
+		return valueMap.hasOwnProperty(propName);
+    }
+    
+    public function deleteProperty(propName:String):void
+    {
+        delete valueMap[propName];
+    }
+	
+	public function elementNames():Array
+	{
+		var names:Array = [];
+		for (var p:String in valueMap)
+			names.push(p);
+		return names;
+	}
+}
+
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/manualtests/ProxyTest/build.xml
----------------------------------------------------------------------
diff --git a/manualtests/ProxyTest/build.xml b/manualtests/ProxyTest/build.xml
new file mode 100644
index 0000000..2e1bcb7
--- /dev/null
+++ b/manualtests/ProxyTest/build.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0"?>
+<!--
+
+  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.
+
+-->
+
+
+<project name="proxytest" default="main" basedir=".">
+    <property name="FLEXJS_HOME" location="../.."/>
+    <property name="example" value="ProxyTest" />
+    
+    <property environment="env"/>
+    <property file="${FLEXJS_HOME}/build.properties"/>
+    <property name="FLEX_HOME" value="${FLEXJS_HOME}"/>
+    <!-- use this to add keep metadata option -->
+    <property name="theme_arg" value="-keep-as3-metadata+=Event" />
+    <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar"
+    type="file"
+    property="FALCON_HOME"
+    value="${env.FALCON_HOME}"/>
+    
+    <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar"
+    type="file"
+    property="FALCON_HOME"
+    value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/>
+    
+    <available file="${env.FALCONJX_HOME}/lib/jsc.jar"
+    type="file"
+    property="FALCONJX_HOME"
+    value="${env.FALCONJX_HOME}"/>
+    
+    <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar"
+    type="file"
+    property="FALCONJX_HOME"
+    value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/>
+    
+    <available file="${env.GOOG_HOME}/closure/goog/base.js"
+    type="file"
+    property="GOOG_HOME"
+    value="${env.GOOG_HOME}"/>
+    
+    <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js"
+    type="file"
+    property="GOOG_HOME"
+    value="${FLEXJS_HOME}/js/lib/google/closure-library"/>
+    
+    <include file="${basedir}/../build_example.xml" />
+
+    <target name="main" depends="clean,build_example.compile,build_example.compilejs"
description="Clean build of FlexJSUI.swc">
+    </target>
+    
+    <target name="clean">
+        <delete dir="${basedir}/bin" failonerror="false" />
+        <delete dir="${basedir}/bin-debug" failonerror="false" />
+        <delete dir="${basedir}/bin-release" failonerror="false" />
+    </target>
+
+</project>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/manualtests/ProxyTest/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/manualtests/ProxyTest/src/MyInitialView.mxml b/manualtests/ProxyTest/src/MyInitialView.mxml
new file mode 100644
index 0000000..9b51ed8
--- /dev/null
+++ b/manualtests/ProxyTest/src/MyInitialView.mxml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+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.
+
+-->
+<js:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009"
+				xmlns:js="library://ns.apache.org/flexjs/basic"
+				xmlns:local="*" 
+				xmlns:models="models.*" 
+				xmlns:acc="org.apache.flex.html.accessories.*">
+	
+	<fx:Style>
+		.title {
+			font-size: 14pt;
+			font-weight: bold;
+		}
+
+	</fx:Style>
+	
+	<fx:Script>
+		<![CDATA[			
+			import org.apache.flex.core.IPopUpHost;
+			import org.apache.flex.events.Event;
+			import org.apache.flex.utils.UIUtils;
+						
+            import org.apache.flex.utils.Proxy;
+            
+            public function runTest():void
+            {
+				var p:Proxy = new Proxy();
+				p.foo = "bar";
+				trace(p.foo);
+				var o:Object = p;
+				// in SWF, this should work, but in JS you should get undefined
+                trace(o.foo);
+				var s:String = p.foo + "bar";
+				trace(s); // barbar
+				p.foo += "bar";
+				trace(p.foo); // barbar
+            }
+		]]>
+	</fx:Script>
+	
+	<js:Container id="cont" width="600" height="700" x="50" y="50">
+		<js:beads>
+			<js:VerticalLayout />
+		</js:beads>
+		
+		<js:Label text="Proxy Test" className="title" />
+		<js:TextButton text="Test" click="runTest()" />
+	</js:Container>
+	
+</js:ViewBase>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/manualtests/ProxyTest/src/ProxyTest.mxml
----------------------------------------------------------------------
diff --git a/manualtests/ProxyTest/src/ProxyTest.mxml b/manualtests/ProxyTest/src/ProxyTest.mxml
new file mode 100644
index 0000000..27e97b5
--- /dev/null
+++ b/manualtests/ProxyTest/src/ProxyTest.mxml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!---
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+-->
+<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+				   xmlns:local="*"
+				   xmlns:models="models.*"
+                   xmlns:controllers="controllers.*"
+				   xmlns:js="library://ns.apache.org/flexjs/basic" 
+				   >
+	
+	<js:valuesImpl>
+		<js:SimpleCSSValuesImpl />
+	</js:valuesImpl>
+    <js:controller>
+        <controllers:MyController />
+    </js:controller>
+    <js:model>
+        <models:MyModel />
+    </js:model>
+	<js:initialView>
+		<local:MyInitialView />
+	</js:initialView>
+</js:Application>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/manualtests/ProxyTest/src/README.txt
----------------------------------------------------------------------
diff --git a/manualtests/ProxyTest/src/README.txt b/manualtests/ProxyTest/src/README.txt
new file mode 100644
index 0000000..f38df7f
--- /dev/null
+++ b/manualtests/ProxyTest/src/README.txt
@@ -0,0 +1,45 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+DESCRIPTION
+
+The FormExample application demonstrates several FlexJS components and how they
+can be aligned in a column, much like you would see in a form. 
+
+This Flex application may be run as a Flash SWF or cross-compiled (using Falcon JX)
+into JavaScript and HTML and run without Flash.
+
+The components are placed into a Container with a VerticalColumnLayout bead. This bead
+examines each of the children in the Container and aligns them in two columns.
+
+COMPONENTS and BEADS
+
+- Container
+- DateField
+- Label
+- TextInput
+
+- NonVirtualVerticalLayout
+- NumericOnlyTextInputBead
+- VerticalColumnLayout
+
+NOTES
+
+The cross-compilation to JavaScript often results in non-fatal warnings. Some of these warnings
+should be addressed in future releases of the Falcon JX compiler.

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/manualtests/ProxyTest/src/controllers/MyController.as
----------------------------------------------------------------------
diff --git a/manualtests/ProxyTest/src/controllers/MyController.as b/manualtests/ProxyTest/src/controllers/MyController.as
new file mode 100644
index 0000000..0d72c69
--- /dev/null
+++ b/manualtests/ProxyTest/src/controllers/MyController.as
@@ -0,0 +1,52 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 controllers
+{
+	import org.apache.flex.events.Event;
+	
+	import org.apache.flex.core.Application;
+	import org.apache.flex.core.IDocument;
+    
+    import models.MyModel;
+    	
+	public class MyController implements IDocument
+	{
+		public function MyController(app:Application = null)
+		{
+			if (app)
+			{
+				this.app = app as ProxyTest;
+				app.addEventListener("viewChanged", viewChangeHandler);
+			}
+		}
+		
+		private var app:ProxyTest;
+		
+		private function viewChangeHandler(event:Event):void
+		{
+		}
+		        
+		public function setDocument(document:Object, id:String = null):void
+		{
+			this.app = document as ProxyTest;
+			app.addEventListener("viewChanged", viewChangeHandler);
+		}
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/390a1d87/manualtests/ProxyTest/src/models/MyModel.as
----------------------------------------------------------------------
diff --git a/manualtests/ProxyTest/src/models/MyModel.as b/manualtests/ProxyTest/src/models/MyModel.as
new file mode 100644
index 0000000..5a16d02
--- /dev/null
+++ b/manualtests/ProxyTest/src/models/MyModel.as
@@ -0,0 +1,125 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 models
+{
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.EventDispatcher;
+	
+	public class MyModel extends EventDispatcher
+	{
+		public function MyModel()
+		{
+		}
+		
+		private var _requestedField:String = "Ask";
+		
+		[Bindable("requestedFieldChanged")]
+		public function get requestedField():String
+		{
+			return _requestedField;
+		}
+		
+		public function set requestedField(value:String):void
+		{
+			if (value != _requestedField)
+			{
+				_requestedField = value;
+				dispatchEvent(new Event("requestedFieldChanged"));
+				if (_responseData)
+					dispatchEvent(new Event("responseTextChanged"));
+			}
+		}
+		
+		[Bindable("responseTextChanged")]
+		public function get responseText():String
+		{
+			if (_responseData == null)
+				return "";
+			if (_responseData == "No Data")
+				return _responseData as String;
+			var s:String = _responseData[_requestedField];
+			if (s == null)
+			{
+				if (_requestedField == "Ask")
+					s = _responseData["Bid"];
+			}
+			return s;
+		}
+		
+		private var _responseData:Object;
+		
+		[Bindable("responseDataChanged")]
+		public function get responseData():Object
+		{
+			return _responseData;
+		}
+		
+		public function set responseData(value:Object):void
+		{
+			if (value != _responseData)
+			{
+				_responseData = value;
+				_allData = "";
+				dispatchEvent(new Event("responseDataChanged"));
+				dispatchEvent(new Event("responseTextChanged"));
+			}
+		}
+		
+		private var _allData:String = "";
+		
+		[Bindable("responseDataChanged")]
+		public function get allData():String
+		{
+			if (_allData == "" && _responseData != null)
+			{
+				for (var p:String in _responseData)
+				{
+					_allData += p + ": " + _responseData[p] + "\n";
+				}
+			}
+			return _allData;
+		}
+		
+		
+		private var _stockSymbol:String;
+		
+		[Bindable("stockSymbolChanged")]
+		public function get stockSymbol():String
+		{
+			return _stockSymbol;
+		}
+		
+		public function set stockSymbol(value:String):void
+		{
+			if (value != _stockSymbol)
+			{
+				_stockSymbol = value;
+				dispatchEvent(new Event("stockSymbolChanged"));
+			}
+		}
+
+        private var _strings:Array = ["AAPL", "ADBE", "GOOG", "MSFT", "YHOO"];
+        [Bindable("__NoChangeEvent__")]
+        public function get strings():Array
+        {
+            return _strings;
+        }
+
+	}
+}
\ No newline at end of file


Mime
View raw message