flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [16/21] git commit: [flex-asjs] [refs/heads/spark] - [IMPROVEMENT] Fix of EventDispatcher to support IEventDispatcher implementations, without earlier constructor hack. Added a quick verification test to the DatabindingTestbed test
Date Wed, 07 Sep 2016 19:24:22 GMT
[IMPROVEMENT] Fix of EventDispatcher to support IEventDispatcher implementations, without earlier
constructor hack. Added a quick verification test to the DatabindingTestbed test


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

Branch: refs/heads/spark
Commit: ec4e914e67160addc5494d3bd666aed6cfd1d362
Parents: ed100b7
Author: greg-dove <greg.dove@gmail.com>
Authored: Sat Sep 3 09:35:34 2016 +1200
Committer: greg-dove <greg.dove@gmail.com>
Committed: Sat Sep 3 09:35:34 2016 +1200

----------------------------------------------------------------------
 .../org/apache/flex/events/EventDispatcher.as   | 32 +++++----
 .../DataBindingTestbed/src/MyInitialView.mxml   | 71 ++++++++++++++++----
 2 files changed, 75 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ec4e914e/frameworks/projects/Core/src/main/flex/org/apache/flex/events/EventDispatcher.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/EventDispatcher.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/EventDispatcher.as
index d4bc1a9..0d2b081 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/EventDispatcher.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/EventDispatcher.as
@@ -59,22 +59,11 @@ package org.apache.flex.events
 	COMPILE::JS
 	public class EventDispatcher extends goog.events.EventTarget implements IEventDispatcher
 	{
+		
+		private var _target:IEventDispatcher;
         public function EventDispatcher(target:IEventDispatcher = null)
         {
-            if (target != null) {
-				setTargetForTesting(target);
-				//the following can be required with IEventDispatcher implementation instead of extending
EventDispatcher
-				//(fireListeners is not required by IEventDispatcher, but is called on the 'currentTarget'
-				//by the ancestor goog.events.EventTarget code)
-				var obj:Object = target;
-				if (!obj.fireListeners) {
-					var me:EventDispatcher = this;
-					obj.fireListeners = function ():* {
-						me.fireListeners.apply(me,arguments);
-					};
-				}
-			}
-                
+			_target = target || this;
         }
         
         public function hasEventListener(type:String):Boolean
@@ -86,6 +75,21 @@ package org.apache.flex.events
 		{
 			try 
 			{
+				//we get quite a few string events here, "initialize" etc
+				//so this general approach doesn't work:
+				//event.target = _target;
+				if (event) {
+					if (typeof event == "string") {
+						event = new Event(event as String);
+						event.target = _target;
+						//console.log("created event from string ",event);
+					}
+					else if ("target" in event) {
+						event.target = _target;
+						//console.log("assigned target to event ",event);
+					}
+				} else return false;
+
 				return super.dispatchEvent(event);
 			}
 			catch (e:Error)

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ec4e914e/manualtests/DataBindingTestbed/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/manualtests/DataBindingTestbed/src/MyInitialView.mxml b/manualtests/DataBindingTestbed/src/MyInitialView.mxml
index 3f16bfa..3f788fe 100644
--- a/manualtests/DataBindingTestbed/src/MyInitialView.mxml
+++ b/manualtests/DataBindingTestbed/src/MyInitialView.mxml
@@ -102,42 +102,85 @@ limitations under the License.
 					
 					StaticTimer.initStaticTimer();
 					try{
-					  instTimer = new InstanceTimer();
+					  	instTimer = new InstanceTimer();
 					} catch (e:Error) {
 						addErrorReport("problem instantiating InstanceTimer ",e);
 					}
+					try{
+					  if (instTimer) {
+						  Object(instTimer).addEventListener("testinstTimer",testEventTarget);
+						  _expectedTarget=instTimer;
+						  Object(instTimer).dispatchEvent(new Event("testinstTimer"));
+						  Object(instTimer).removeEventListener("testinstTimer",testEventTarget);
+					  }
+					} catch (e:Error) {
+						 addErrorReport("problem with explicit dispatching from InstanceTimer ",e);
+					}		
 					
 					try {
 						var test:Object = new BindableSubVO1()
 					} catch (e:Error) {
 						addErrorReport("problem instantiating BindableSubVO1 ",e);
 					}
+					
+					try{
+					  if (test) {
+						  test.addEventListener("testBindableSubVO1",testEventTarget);
+						  _expectedTarget=test;
+						  test.dispatchEvent(new Event("testBindableSubVO1"));
+						  test.removeEventListener("testBindableSubVO1",testEventTarget);
+					  
+					  }
+					} catch (e:Error) {
+						addErrorReport("problem with explicit dispatching from BindableSubVO1 ",e);
+					}		
+					
+					
 					test=null;
 					try {
-					   test = new BindableSubVO2();
+						test = new BindableSubVO2();
 					} catch (e:Error) {
 						addErrorReport("problem instantiating BindableSubVO2 ",e);
 					}
-					
-					try {
-					   if (test) {
-							//remove the EventDispatcher constructor hack in js
-						//	if (test.fireListeners) delete test.fireListeners;
-							test.fieldofBindableSubVO2 = "otherValue";
-					   }
-					  
+
+					try{
+						if (test) {
+							test.addEventListener("testBindableSubVO2",testEventTarget);
+							_expectedTarget=test;
+							test.dispatchEvent(new Event("testBindableSubVO2"));
+							test.removeEventListener("testBindableSubVO2",testEventTarget);
+
+						}
 					} catch (e:Error) {
-						addErrorReport("problem dispatching events on BindableSubVO2 ",e);
+						addErrorReport("problem with explicit dispatching from BindableSubVO2 ",e);
 					}
-					
-					test=null;
+
+
+				test=null;
 					try {
 						test = new BindableSubVO3()
 					} catch (e:Error) {
 						addErrorReport("problem instantiating BindableSubVO3 ",e);
 					}
+					try{
+						if (test) {
+							test.addEventListener("testBindableSubVO3",testEventTarget);
+							_expectedTarget=test;
+							test.dispatchEvent(new Event("testBindableSubVO3"));
+							test.removeEventListener("testBindableSubVO3",testEventTarget);
+
+						}
+					} catch (e:Error) {
+						addErrorReport("problem with explicit dispatching from BindableSubVO3 ",e);
+					}
 					
-					
+			}
+			
+			private var _expectedTarget:Object;
+			private function testEventTarget(event:Event):void{
+				if (event.target!=_expectedTarget) {
+					addErrorReport("unexpected event target "+event.type,new Error("unexpected event target"));
+				}
 			}
 			
 			


Mime
View raw message