Last active
July 9, 2020 03:20
Typesafe version of `flash.events.EventDispatcher` to make the Flash API suck a little less. Would also work for `js.html.EventTarget`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flash.events; | |
extern class EventDispatcher implements IEventDispatcher { | |
function new(?target:IEventDispatcher) : Void; | |
function addEventListener<T:Event>(type:EventType<T>, listener: T->Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void; | |
function dispatchEvent(event:Event):Bool; | |
function hasEventListener(type:String):Bool; | |
function removeEventListener<T:Event>(type:EventType<T>, listener: T->Void, useCapture:Bool = false):Void; | |
function toString():String; | |
function willTrigger(type:String):Bool; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flash.events; | |
abstract EventType<T:Event>(String) from String to String {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flash.events; | |
extern interface IEventDispatcher { | |
function addEventListener<T:Event>(type:EventType<T>, listener: T->Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void; | |
function dispatchEvent(event:Event):Bool; | |
function hasEventListener(type:String):Bool; | |
function removeEventListener<T:Event>(type:EventType<T>, listener: T->Void, useCapture:Bool = false):Void; | |
function toString():String; | |
function willTrigger(type:String):Bool; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flash.event.*; | |
extern class ProgressEvent extends Event { | |
var bytesLoaded:Float; | |
var bytesTotal:Float; | |
function new(type:EventType<ProgressEvent>, bubbles:Bool = false, cancelable:Bool = false, bytesLoaded:Float = 0, bytesTotal:Float = 0) : Void; | |
static var PROGRESS(default, null):EventType<ProgressEvent>; | |
static var SOCKET_DATA(default, null):EventType<ProgressEvent>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import flash.events.*; | |
class Usage { | |
static function main() { | |
var source = new EventDispatcher(); | |
source.addEventListener(ProgressEvent.PROGRESS, function (e) $type(e));//yields ProgressEvent | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment