Skip to content

Commit

Permalink
add getThis() helper method
Browse files Browse the repository at this point in the history
See the comment section of HaxeFoundation/haxe@e3a022d
  • Loading branch information
andyli committed Jul 25, 2017
1 parent 4aa9b8c commit 4a6e3d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions generate.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-main js.jquery.ExternGenerator
-lib mcli
--macro allowPackage('js')
--macro exclude('js.html.compat')
# -cmd neko ExternGenerator.n --api-xml api.xml --output-folder .
-cmd neko ExternGenerator.n --api-xml api.xml --output-folder . --pack js.jquery --native '$' --use-element --use-haxe-either --use-haxe-rest --no-seperated-static --no-rename-static-field --add-haxe-iterator
# -cmd neko ExternGenerator.n --api-xml api.xml --output-folder ~/Library/Caches/Homebrew/haxe--git/std --pack js.jquery --native '$' --no-build --use-element --use-haxe-either --use-haxe-rest --no-seperated-static --no-rename-static-field --add-haxe-iterator
5 changes: 5 additions & 0 deletions js/jquery/Event.hx
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,9 @@ package js.jquery;
**/
public var view : js.html.Window;
/**
A convenient method of getting `$(this)`, which is typically the same as `$(evt.currentTarget)`.
For detail, refer to https://api.jquery.com/event.currenttarget/.
**/
inline public function getThis():js.jquery.JQuery return new js.jquery.JQuery(js.Lib.nativeThis);
}
24 changes: 24 additions & 0 deletions js/jquery/ExternGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,30 @@ class ExternGenerator #if (mcli && !macro) extends CommandLine #end {
}
var evtFields:Array<Dynamic> = getFields("js.html.Event");
td.fields = td.fields.filter(function(field) return !evtFields.exists(function(f) return f.name == field.name));

// add getThis() helper method
// See the comment section of https://github.com/HaxeFoundation/haxe/commit/e3a022dd4bae85f8456cf3f1683fefd2e0b5d22d
{
var jq = jqType("JQuery");
var JqTPath = switch (jq) {
case TPath(tp): tp;
case v: throw v;
}
td.fields.push({
name: "getThis",
doc: "A convenient method of getting `$(this)`, which is typically the same as `$(evt.currentTarget)`.\n"
+ "For detail, refer to https://api.jquery.com/event.currenttarget/.",
access: [AInline, APublic],
kind: FFun({
params: null,
args: [],
ret: jq,
expr: macro return new $JqTPath(js.Lib.nativeThis),
}),
meta: [],
pos: null
});
}
default:
//pass
}
Expand Down

0 comments on commit 4a6e3d5

Please sign in to comment.