On 12/2/15, 12:12 PM, "Josh Tynjala" <joshtynj...@gmail.com> wrote:

>You'd lose out on compiler checks and IDE code hinting if you had to call
>require() directly in AS.

I probably don't know enough about Node and require to understand that.
Let's try looking at source code patterns first. My quick read of require
is that it is somewhat like Promises or the Flex ModuleLoader.  I would
imagine that require() returns an Object.  Your AS code might then look
like:

import FS;
...
var fs:FS = require("fs") as FS;

You would have an external-library-path pointing to an FS.swc or maybe a
Node.swc full of externs for these modules and FS would have its exported
APIs defined in that externs file:

---- FS.as ----
public class FS
{
  public function readFileSync(...) {}
  public function readStream(...) {};
}
---- FS.as ----

Or am I just totally missing the point?  I suppose you could go one level
fancier and make wrappers like this:

---- FS.as ----
public class FS
{

private static function getInstance():FS
{
  return require("fs") as FS;
}
  public function readFileSync(...) { getInstance().readFileSync()}
  public function readStream(...) { getInstance().readStream()};
}

Then I think folks could just instantiate an FS and never call require
because the FS wrapper would call require for you.
Then your app code would look like:

import FS;
...
var fs:FS = new FS();




Of course, I could be wrong...
-Alex

Reply via email to