haxe-modular icon indicating copy to clipboard operation
haxe-modular copied to clipboard

Expose sync/async option when loading bundle

Open kevinresol opened this issue 7 years ago • 10 comments

This is mainly for electron. Because I would have to add -lib hxnodejs to enable some nodejs API while I still want to load bundles from remote asynchronously.

kevinresol avatar Aug 24 '18 07:08 kevinresol

I'm a bit confused by Electron, shouldn't the election client NOT have the nodejs flag? Because in my understanding Electron is providing a shim node API to the client. Also this change is going to generate more code for everybody.

elsassph avatar Aug 24 '18 08:08 elsassph

I simply understand electron as allowing one to run node.js scripts in a html file:

<script>
  var fs = require('fs');
  fs.createReadStream(...);
</script>

So I have always been simply adding -lib hxnodejs and use all the sys/node features in a electron app.

Also this change is going to generate more code for everybody.

Why? the sync flag is evaluated at compile time and the macro only emits either branch of the code.

kevinresol avatar Aug 24 '18 09:08 kevinresol

Aha, pardon my ignorance, so there really is the full node API basically in the browser context?

Because what I've seen is reports that when Haxe thinks it's nodeJS it uses a different Http implementation which doesn't work in Electron...

elsassph avatar Aug 24 '18 10:08 elsassph

Yes as far as I understand

kevinresol avatar Aug 24 '18 10:08 kevinresol

I don't know about haxe http, I always use fetch in electron

kevinresol avatar Aug 24 '18 10:08 kevinresol

You know we may as well just explicitly #if electron

elsassph avatar Aug 24 '18 11:08 elsassph

@kevinresol not sure it's still a need for you but -D nodejs should provide you with the synchronous node behaviour you are looking for.

elsassph avatar Jul 22 '19 13:07 elsassph

The problem here is that I need both async and sync in electron.

sync is for loading node modules async is for loading web modules

kevinresol avatar Jul 22 '19 13:07 kevinresol

From last time I did an Electron app you can use the synchronous require both for the server and client side of the apps - or do you intend to use the same build for Electron and a web app?

elsassph avatar Jul 22 '19 14:07 elsassph

As I said in OP I need to load bundles from remote asynchronously. Both sync and async are needed in the same build, a single js output.

kevinresol avatar Jul 22 '19 17:07 kevinresol