You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2017/05/30 19:48:13 UTC

[38/50] git commit: [flex-asjs] [refs/heads/tlf] - add EventLogging bead to try to catch type errors

add EventLogging bead to try to catch type errors


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

Branch: refs/heads/tlf
Commit: bf404b1cc8ae55299756367612ea195aa1d2fe02
Parents: 9c58972
Author: Alex Harui <ah...@apache.org>
Authored: Tue May 30 11:29:45 2017 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue May 30 11:29:45 2017 -0700

----------------------------------------------------------------------
 .../org/apache/flex/core/EventLoggingBead.as    | 124 +++++++++++++++++++
 .../Core/src/main/resources/basic-manifest.xml  |   1 +
 2 files changed, 125 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/bf404b1c/frameworks/projects/Core/src/main/flex/org/apache/flex/core/EventLoggingBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/EventLoggingBead.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/EventLoggingBead.as
new file mode 100644
index 0000000..96bd920
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/EventLoggingBead.as
@@ -0,0 +1,124 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.core
+{
+    COMPILE::SWF
+    {
+        import flash.events.Event;
+    }
+    
+    import org.apache.flex.core.IBead;
+    import org.apache.flex.core.IStrand;
+    import org.apache.flex.events.IEventDispatcher;
+    
+    /**
+     *  The EventLogging bead logs dispatches
+	 *  of certain events.  This can be useful
+	 *  in debugging type coercion errors when
+	 *  an event handler has the wrong type
+	 *  in the function signature.
+     *  
+	 *  Place this bead in the application.
+	 *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+	public class EventLoggingBead implements IBead
+	{
+        /**
+         *  Constructor.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public function EventLoggingBead()
+		{
+			super();
+		}
+        
+        private var _strand:IStrand;
+        
+        /**
+         *  @copy org.apache.flex.core.IBead#strand
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+		 *
+		 *  @flexjsignorecoercion org.apache.flex.events.IEventDispatcher
+         */
+        public function set strand(value:IStrand):void
+        {
+            _strand = value;
+			
+			COMPILE::SWF
+			{
+			if (eventNames)
+			{
+				// log each event.  Use capture phase to try to get it first.
+				for each (var e:String in eventNames)
+					(_strand as IEventDispatcher).addEventListener(e, eventHandler, true);
+			}
+			}
+        }    
+
+        private var _eventNames:Array;
+        
+        /**
+         *  Array of event names to listen to.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function get eventNames():Array
+        {
+			return _eventNames;
+        }
+        
+		public function set eventNames(value:Array):void
+		{
+			_eventNames = value;
+		}
+		
+		private var _log:Array = [];
+		
+		public function get log():Array
+		{
+			return _log;
+		}
+		
+        COMPILE::SWF
+        private function eventHandler(event:Event):void
+        {
+			_log.push(event);
+			if (_log.length > 10)
+				_log.shift();
+			trace(event.type + " " + event.target);
+        }
+        
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/bf404b1c/frameworks/projects/Core/src/main/resources/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/resources/basic-manifest.xml b/frameworks/projects/Core/src/main/resources/basic-manifest.xml
index d2c3aa6..1d528e4 100644
--- a/frameworks/projects/Core/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Core/src/main/resources/basic-manifest.xml
@@ -23,6 +23,7 @@
 
     <component id="SimpleCSSValuesImpl" class="org.apache.flex.core.SimpleCSSValuesImpl"/>
     <component id="CSSFontFaceBead" class="org.apache.flex.core.CSSFontFaceBead" />
+    <component id="EventLoggingBead" class="org.apache.flex.core.EventLoggingBead" />
     <component id="BrowserScroller" class="org.apache.flex.core.BrowserScroller"/>
     <component id="BrowserResizeHandler" class="org.apache.flex.core.BrowserResizeListener"/>
     <component id="SimpleValuesImpl" class="org.apache.flex.core.SimpleValuesImpl"/>