About Haxe JS support

135 views
Skip to first unread message

David Mouton

unread,
Oct 22, 2014, 10:09:55 AM10/22/14
to haxe...@googlegroups.com
I think the JS support could be better typed.

For example, we could not use Enum in addEventListener?

@:native("HTMLButtonElement")
extern class ButtonElement extends Element
{
   
function addEventListener( type : MouseEventType, listener : Event<MouseEventType> -> Void, ?useCapture : Bool ) : Void;

   
function removeEventListener( type : MouseEventType, listener : Event<MouseEventType> -> Void, ?useCapture : Bool ) : Void;

}

typedef MouseEvent = Event<MouseEventType>;

@:enum abstract
MouseEventType(String) from String to String {  

    var CLICK='click';
    var MOUSE_MOVE='mousemove';
    var MOUSE_DOWN='mousedown';
    var MOUSE_UP='mouseup';
    var MOUSE_OUT='mouseout';
    var MOUSE_OVER='mouseover';
    var SCROLL='scroll';
}


otherwise you could just use constants like :

class MouseEventType {
    static public inline var CLICK:String='click';
    static public inline var MOUSE_MOVE:String='mousemove';
    static public inline var MOUSE_DOWN:String='mousedown';
    static public inline var MOUSE_UP:String='mouseup';
    static public inline var MOUSE_OUT:String='mouseout';
    static public inline var MOUSE_OVER:String='mouseover';
    static public inline var SCROLL:String='scroll';
}


What do you think?

Benjamin Dubois

unread,
Oct 22, 2014, 4:01:16 PM10/22/14
to haxe...@googlegroups.com
I don't get your point. You are only defining String constants.

Using enum allow to constrain to the enum values only.
And anyway since its an abstract enum of String, it's converted into String at compile time anyway.

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

David Mouton

unread,
Oct 23, 2014, 11:50:01 AM10/23/14
to haxe...@googlegroups.com
my goal is to stop declaring my event types by hand

writing this.addEventListener('blabla',blablaHandler) is really annoying.

Especially when they are known : https://developer.mozilla.org/en-US/docs/Web/Events

Using constants instead of 'blabla' is easy and I would have loved to have them in the standard library.

And Using enums would be even better.

you know?

clemos

unread,
Oct 23, 2014, 12:26:17 PM10/23/14
to haxe...@googlegroups.com

Hey,

We wanted to do something like that in hxnodejs,
Nicolas gave us some pretty awesome ideas, which you can read here:
https://github.com/HaxeFoundation/hxnodejs/issues/21
I agree it would be great to use the same pattern in "browser" js externs.

Best
Clément

Juraj Kirchheim

unread,
Oct 23, 2014, 9:36:15 PM10/23/14
to haxe...@googlegroups.com
Has been discussed and rejected here: https://github.com/HaxeFoundation/haxe/issues/3149

Although if for some reason the previous rejection no longer applies, I'm all for it ;)

clemos

unread,
Oct 24, 2014, 6:11:16 AM10/24/14
to haxe...@googlegroups.com
I'm not fully aware of how these externs are generated, 
but I think it would be nice to add our own constraints when possible.

Clément

Benjamin Dubois

unread,
Oct 24, 2014, 3:58:51 PM10/24/14
to haxe...@googlegroups.com
Sorry I read you wrong :
I thought you were saying EvenType are Enum and should be constant instead.

And you were stating the opposite

So :
+1 for event name using abstract Enums
Reply all
Reply to author
Forward
0 new messages