Comments (18)
Meanwhile a nice article about AMD: http://addyosmani.com/writing-modular-js/
from saltarellecompiler.
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.
Forum discussion: http://saltarellecompiler.freeforums.org/module-support-t3.html
from saltarellecompiler.
Why the forum, discussions in here are far better.
from saltarellecompiler.
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.
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.
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.
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.
I guess Module.Require would need only a simple mapping to the require method.
from saltarellecompiler.
My arguments to why github is better:
- It is a centralized place, no external stuff needed, the code is here, the issues and discussions should be here too.
- Everybody has or needs a github account anyway nowadays.
- There is no difference between the logging in process here and the forum.
- 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.
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.
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.
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.
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.
A node module?
Are you talking about exports?
from saltarellecompiler.
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.
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.
The upcoming release 1.5.0 will support CommonJS modules (eg. Node) as well as AMD.
from saltarellecompiler.
Related Issues (20)
- [2.6.2] Canceled tasks should throw TaskCanceledException instead of InvalidOperationException HOT 3
- Status? HOT 1
- [2.6.2] Combining async, finally and IList/IEnumerable results in an incorrect execution workflow HOT 3
- Bridge.NET Acquires Saltarelle HOT 54
- Boolean XORs generate incorrect result HOT 1
- Non-serializable properties for serializable types HOT 1
- int.Parse() gets translated to parseInt(), which isn't precise HOT 4
- Bug in inheritance? HOT 3
- INTERNAL ERROR: ResolveResult ConversionResolveResult HOT 6
- Add support for InternalsVisibleTo attribute HOT 3
- [2.7.0] Asynchronous tasks swallow exceptions
- Minifier incorrectly minifies '+ ++' into '+++'
- When using [NamedValuesAttribute] on an enum, that enum's values are not compiled correctly when used as default parameters HOT 3
- If the data exict HOT 1
- Saltarelle.Runtime HOT 1
- Saltarelle rewrites Mixing expression $.expr[':'] to $["expr[':']"] HOT 1
- Provide toString override for Exception class, otherwise uncaught exceptions will end up logged as [object Object]
- ss_Int32.tryParse returns 0 when value can't be parsed (when input does not match regexp)
- Dictionary issue on Chrome HOT 3
- Saltarelle.Compiler 2.7.0 - INTERNAL ERROR: System.TypeLoadException
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from saltarellecompiler.