try-haxe
try-haxe copied to clipboard
changes to make it work on haxe 4
When building on haxe 4 you'll get :
src/Api.hx:7: characters 8-25 : Type not found : haxe.web.Dispatch
src/Editor.hx:8: characters 8-17 : Type not found : js.JQuery
This is due to these haxe 4 changes :
all : moved haxe.web.Dispatch into hx3compat library (https://github.com/HaxeFoundation/hx3compat).
js : js.JQuery and js.SWFObject were moved into hx3compat library (https://github.com/HaxeFoundation/hx3compat)
1. Add hx3compat library
In the build.hxml
add -lib hx3compat
before and after --next
2. Adjust imports due to depreciation
There's a few changes in the source to adapt to the new syntax like changing all instances of :
-import js.JQuery;
+import js.jquery.JQuery;
3. Typing of events :
Change all instances of
-(e : JqEvent)
+(e : js.jquery.Event)
4. The library array had some typing issues :
if( program.libs != null ){
for( lib in libs.find("input.lib") ){
- if( program.libs.has( lib.val() ) ){
- lib.attr("checked","checked");
+ if( program.libs.has( new JQuery(lib).val() ) ){
+ new JQuery(lib).attr("checked","checked");
}else{
- lib.removeAttr("checked");
+ new JQuery(lib).removeAttr("checked");
}
}
}
- libs.push(i.val());
+ libs.push(new JQuery(i).val());
5. Button methods
And I wasn't sure where the .button*
methods were defined, as they were missing now. These changes made buttons work for me :
-compileBtn.buttonLoading();
+untyped compileBtn.button('loading');
- new JQuery(".link-btn, .fullscreen-btn")
- .buttonReset()
+ untyped new JQuery(".link-btn, .fullscreen-btn")
+ .button('reset')
- compileBtn.buttonReset();
+ untyped compileBtn.button('reset');
Note : These are not optimal changes, just the ones that made try.haxe work with haxe 4 for me.
Thanks ! It would be nice to make a PR with these changes, I would happily merge it :) Also, please use conditional compilation like :
#if (haxe_ver >= 4)
import js.jquery.JQuery;
#else
import js.JQuery;
#end
As for buttons (5), the bootstrap methods are defined here: https://github.com/clemos/haxe-bootstrap
Weird that they are not available any more.
This is probably related to (4): maybe some JQuery signatures have changed, and compileBtn
(or lib
) is not typed as JQuery
but as Element
or something.
I think that would be okay, but first try.haxe.org should support haxe version switching, right?
Because there are definitely big changes between the current haxe 3 and the upcoming haxe 4 - not sure try.haxe should be fully on haxe 4 yet. Would be nice to be able to switch between rc versions and run code there.
When I made as3hx.spacemages.com based on this repo, I did a Docker approach. Could have multiple haxe versions compiled in the Dockerfile, and then support different haxe versions by switching the command line haxe path.
And yeah, I was confused with the bootstrap buttons - wasn't able to find the methods quickly so hacked it with untyped
- that's on me. I'm sure there's a proper way.