royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yish...@apache.org
Subject [royale-asjs] branch develop updated: First implementation of ThrottleBead
Date Sun, 17 Dec 2017 14:18:02 GMT
This is an automated email from the ASF dual-hosted git repository.

yishayw pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new e04299c  First implementation of ThrottleBead
e04299c is described below

commit e04299c8108be96923913222b8991bd786f73fd9
Author: DESKTOP-RH4S838\Yishay <yishayjobs@hotmail.com>
AuthorDate: Sun Dec 17 16:17:25 2017 +0200

    First implementation of ThrottleBead
---
 .../Basic/src/main/resources/basic-manifest.xml    |   1 +
 .../org/apache/royale/html/beads/ThrottleBead.as   | 122 +++++++++++++++++++++
 2 files changed, 123 insertions(+)

diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index 0aba42a..834280b 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -114,6 +114,7 @@
      -->
 
     <component id="GetScrollbarWidth" class="org.apache.royale.html.beads.GetScrollbarWidth"/>
+    <component id="ThrottleBead" class="org.apache.royale.html.beads.ThrottleBead"/>
     <component id="UnselectableElementBead" class="org.apache.royale.html.beads.UnselectableElementBead"/>
     <component id="DisableBead" class="org.apache.royale.html.beads.DisableBead" />
     <component id="DisabledAlphaBead" class="org.apache.royale.html.beads.DisabledAlphaBead"
/>
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ThrottleBead.as
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ThrottleBead.as
new file mode 100644
index 0000000..50e9a2b
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ThrottleBead.as
@@ -0,0 +1,122 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads
+{
+	
+	import org.apache.royale.core.IBead;
+	import org.apache.royale.core.IStrand;
+	import org.apache.royale.events.Event;
+	import org.apache.royale.events.IEventDispatcher;
+	import org.apache.royale.events.EventDispatcher;
+	COMPILE::SWF {
+		import flash.utils.clearTimeout;	
+		import flash.utils.setTimeout;	
+	}
+
+	/**
+     *  Dispatched when the event first fires
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9
+     */
+    [Event(name="startingThrottle", type="org.apache.royale.events.Event")]
+    /**
+     *  Dispatched after the timeout occurs
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9
+     */
+
+    [Event(name="finishedTrottle", type="org.apache.royale.events.Event")]
+	/**
+	 *  The ThrottleBead class allows you to listen to an event only after a timeout
+	 *  has been reached. This can be useful in situations where events are thrown repeatedly
+	 *  but the application is only interested in the last dispatching.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.0
+	 */
+
+	public class ThrottleBead extends EventDispatcher implements IBead
+	{
+		/**
+		 *  constructor.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.0
+		 */
+		public function ThrottleBead()
+		{
+		}
+		
+		private var _strand:IStrand;
+		public var event:String;
+		public var interval:Number = 500;
+		private var timeoutId:Number = NaN;
+		
+		/**
+		 *  @copy org.apache.royale.core.IBead#strand
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9
+		 */
+		public function set strand(value:IStrand):void
+		{	
+			_strand = value;
+			host.addEventListener(event, originalEventDispatched);
+		}
+		
+		private function originalEventDispatched():void
+		{
+			if (isNaN(timeoutId))
+			{
+				timeoutId = setTimeout(throwEventWhenFinished, interval);
+				dispatchEvent(new Event("startingThrottle"));
+			} else
+			{
+				clearTimeout(timeoutId);
+				timeoutId = setTimeout(throwEventWhenFinished, interval);
+			}
+		}
+
+		private function get host():IEventDispatcher
+		{
+			return _strand as IEventDispatcher;
+		}
+		
+		private function throwEventWhenFinished():void
+		{
+			clearTimeout(timeoutId);
+			timeoutId = NaN;
+			dispatchEvent(new Event("finishedTrottle"));
+		}
+
+		
+	}
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@royale.apache.org" <commits@royale.apache.org>'].

Mime
View raw message