GithubHelp home page GithubHelp logo

Comments (18)

txdv avatar txdv commented on June 14, 2024

Meanwhile a nice article about AMD: http://addyosmani.com/writing-modular-js/

from saltarellecompiler.

dested avatar dested commented on June 14, 2024

Im not sure if it makes sense to have createserver be a static method on HTTP. I feel like it should be an instance method on it, with the instantiation of Http emit the "require" code. (with the proper decoration)

Im afraid I cant give a lot of input on amd, but there would have to be some sort of class dependencies or something to that effect so you can properly pass them into the module. Functionally what would be the benefit to emitting the class as an amd module?

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 14, 2024

Forum discussion: http://saltarellecompiler.freeforums.org/module-support-t3.html

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

Why the forum, discussions in here are far better.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 14, 2024

The idea behind the forum is to give people a place to ask questions rather than sending them to me by email. I am not sure wether it's better to discuss features here or in a forum. Now I know your opinion, but I don't know your arguments.

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

Your binding prototype fits with the http.createServer API, but it is just a convenience method.

exports.createServer = function(requestListener) {
  return new Server(requestListener);
};

but there is also the class constructor function:

exports.Server = Server;

So proposal would be to map it like this:

public class HttpServer
{
    public HttpServer(Action<Request, Response> callback);
    public event Action OnClose; // and all the other events similar like this
    public void Close():
    public void Listen(int port);
    public void Listen(int port, string hostname);
    // etc
}

public static class Http
{
    public HttpServer CreateServer(Action<Request, Response> callback);
}

Both methods are now exposed. CreateServer returns an HttpServer, it is easy to chain with Listen than creating it with new:

(new Server(/* callback */)).Listen(8000);
Http.CreateServer(/* callback */)).Listen(8000);

That is why createServer exists.

Now in this particular case we would like to have an attribute for the static method to tell the compiler that it should load the http module with require.

[NodeModule('http')]
public static class Http

As well for the HttpServer

public class HttpServer
{
    [NodeModule('http', 'Server')];
    public HttpServer(Action<Request, Response> callback);

This is how I would do it for the blocking require version. I would also expose it in a stand alone version like this:

public static class Module
{
    public static object Require(string name)
    {
        // compiler magic
        return null;
    }
    public static T Require<T>(string name)
    {
        return Require(name) as T;
    }
}

So the user can have access to it. This class will come in handy when adding AMD functionality as well, because that one can't be implemented without an a function with a callback or at least the user should have the ability to use the function when he desires.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 14, 2024

Thanks for this lengthy post. So, what would the generated code look like for this:

(new Server(/* callback */)).Listen(8000);
Http.CreateServer(/* callback */)).Listen(8000);

?
Would it be something like

var $http = require('http');
new $http.Server(/* callback */).listen(8000);
$http.createServer(/* callback */).listen(8000);

?

Also, I think the NodeModule attribute would need to go on the type rather than the constructor. Right?

What compiler magic would you need in the Module.Require class?

And finally, how could attributes be created that would allow the generated script to be used as a node module? What would the generated code look like?

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

Well, maybe someone wants to define his own constructors, so you need to select somehow the constructors which use the function constructor in javascript.
So you could do:

[NodeModule('http')]
public class HttpServer
{
    [ScriptName('Server')]
    public HttpServer(Action<Request, Response> callback) { /* empty body */ }

    [NonScriptable] // I hope this one is right
    public HttpServer()
    {
        // the user can do something that he wants to while reusing the other constructor
    }

So in conjuction with NodeModule the compiler will know that it has to call require('http').Server.

About the generated code now: I just tested

require('http') === require('http')

It returns true, so if one is really lazy, the code emmited could look like:

require('http').Server(/* callback */).listen(80000);
require('http').createServer(/* callback */).listen(80000);

But I would prefer your approach, but instead of a specific hard variable like $http, you would just use the next in line, $a, $b, $c

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

I guess Module.Require would need only a simple mapping to the require method.

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

My arguments to why github is better:

  1. It is a centralized place, no external stuff needed, the code is here, the issues and discussions should be here too.
  2. Everybody has or needs a github account anyway nowadays.
  3. There is no difference between the logging in process here and the forum.
  4. markdown instead of bbcode

Github has all this nice markup: http://github.github.com/github-flavored-markdown/
You can reference commits easy, add multiple showcases of code and stuff.
markdown is by far more easier to write than bbcode.
I was so irirated with bbcode, that I have created a markdown to bbcode converter

from saltarellecompiler.

dested avatar dested commented on June 14, 2024

Ill chime in, I was the one who bothered Erik to create the forum. I didnt see it more for issue tracking, but for the developers who are beginning to use saltarelle on a more ongoing basis to communicate with other developers. That way the issue tracker doesnt get cluttered with "CODE WONT COMPILE" kinds of tickets. Also sharing projects and that kind of thing.

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

Feature design is worth an issue imo.
The forum can stay for other questions, I guess I already did open an issue where I just asked for whats the difference between script# and saltarelle.
btw that name saltarelle was hard to remember.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 14, 2024

For the github/forum question, we'll use github, at least for now and we'll see if the forum ever gets any user base.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 14, 2024

For the differient constructors, we already have [AlternateSignature], which should probably suffice here. For the variable names I'm thinking (in non-minimized scripts) that it should try using the module name, but with fallback options if that name is already in use.

I guess the actual syntax for creating the server would be new (require('http').Server(/* callback */)).listen(80000);?

And, how do you think the generated script should look in order for the compiler output to be usable as a module?

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

A node module?
Are you talking about exports?

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 14, 2024

Yes. But not about the syntax, but rather about the desired semantics. Eg, would we want something like

namespace X.Y {
    public class C {
    }
    public class D {
    }
}

namespace Z {
    public class C {
    }
}

to be translated to

/* stuff */
exports.X = {
    Y: { C:  X.Y.C, D: X.Y.D }
}
exports.Z = {
    C: Z.C
}

or something similar?

Or is there a better idea?

from saltarellecompiler.

txdv avatar txdv commented on June 14, 2024

Yeah, I guess that would be the solution.
It would be just like in .NET.
I guess one would reference the .net assemblies and the appropriate .js assembly would be in the same folder.

from saltarellecompiler.

erik-kallen avatar erik-kallen commented on June 14, 2024

The upcoming release 1.5.0 will support CommonJS modules (eg. Node) as well as AMD.

from saltarellecompiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.