Wind.js is Jeffrey Zhao's effort to simplify async development in JavaScript, which comes with a compiler as well as a set of libraries.
I'm a game developer, and please allow me to use "Wear equipments" as an example.
When some player wanner to wear an equipment, we will do following steps:
Ok, let's implement this feature.
Wow, it's really badly smelling!
A lot of "if (err) return cb(err)", callbacks in callbacks, so could this ugly code look better?
Some really brilliant guys (just like Anders) are just wondering if it is possible that code in sync way but comes with async benefits, just like this:
Yes, they did it!
The language designer of C#, Mr. Anders, introduced two new keywords in to C# 5.0, which realised the dream with compiler technology.
Some sync C# code like this:
With just a little bit of modifications:
It's almost the same, but the smart C# 5.0 compiler will compile this into 2 functions, and the latter one will executed async after the load of http request.
Yes, as what you are guessing, Wind.js (by Jeffrey Zhao) has taken this awesome feature to JavaScript with a fully handwritten compiler as well as a set of async libraries.
We can now transform our code in this way:
Isn't it amazing and beautiful?!
First, you need to install wind package with the npm tools:
And then, import the wind module to your source file:
Tips: due to the limitation of current version, you need to name the imported module with exactly 'Wind'
Let's write a simple sample
Done!
Almost all textbooks about JavaScript or any other dynamic language that has eval (just like Python) will tell you that: DO NOT USE eval, cos. it's dangerous, dirty and slow!
So why doesn't Wind.js remove the dependency to eval? Will this be dangerous or slow?
If you wanner a simple answer? It is NO, NO, NO, NO!
Let's look back to the origin of the danger of eval: It's mainly because eval is usually used to simplify some process to user input data.
When you work with Wind.js, all code are written by you (ok, there will be your mate's code), and then compiled with the wind compiler, and then eval for just ONCE.
So, you code is only "eval"ed ONCE, and under your control, it's safe and as fast as your handwritten code.
Currently this project's only contributor is its author Jeffrey Zhao, and we need some more people to join us to do the following work:
We really appreciate all kinds of contributions.
Author: Jeffrey Zhao
Project Site: http://windjs.org/ (currently only in Simplified Chinese)
GitHub Site: https://github.com/JeffreyZhao/wind
NPM Package: wind
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
// Original: function (interval) { while (true) { drawClock(new Date()); $await(Wind.Async.sleep(interval)); } } // Complied: /* async << function (interval) { */ (function (interval) { var _builder_$0 = Wind.builders["async"]; return _builder_$0.Start(this, _builder_$0.While(function () { /* while (true) { */ return true; }, _builder_$0.Delay(function () { /* drawClock(new Date()); */ drawClock(new Date()); /* $await(Wind.Async.sleep(interval)); */ return _builder_$0.Bind(Wind.Async.sleep(interval), function () { return _builder_$0.Normal(); }); }) /* } */ ) ); /* } */ })
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Kind regards, Axel
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Kind regards, Axel
- Compose documents (both in English and Chinese) <LI style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: transparent; MARGIN: 0px; OUTLINE-STYLE: none; OUTLINE-COLOR: invert; PADDING-LEFT: 0px;...
Show original
Kind regards, Axel
Regarding your point 1), there is no difference in the browser: streamline provides a transform API which is just equivalent to the Wind.compile API. I don't understand your point.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
1) I don’t know there’s a transform API in streamline, sorry. If there’s one then using a eval() can do exactly the samething with Wind.js
2) What do you mean callback is called synchronously? If you don’t have any async operations in the method body, Wind.js ould generate a async task which would be executed synchronously.
And yes, with the filter support, we can generate much more compact and readable code. Considering the case of Node.js, I think we can easily add the support in Wind.js as an option.
Kind regards, Axel
this is all very clever, but do code transformations really make callbacks easier?
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
I'm transforming my game server into Wind.js style. And it's really painless and smooth.Wind.js has already provided the Wind.Async.Bindings.fromStandard and Wind.Async.Bindings.fromCallback stubs to help you integrate existing codes.For instance, I already have a EntityStore class which provides standard style interface:EntityStore.prototype = {'get': function(cb) {//...},'save': function(entity,cb) {//...}};In order to make it usable in Wind.js, I just added following codes at the end of the module:['get', 'save'].forEach(function(method) {EntityStore.prototype[method + 'Async'] = Wind.Async.Binding.fromStandard(EntityStore.prototype[method]);});As a result, I can access these methods in Wind.js easily in this way:var users = new EntityStore('user');var currentUser = $await(users.get(userId));
With streamline you don't (except for exists which is a black swan :-( ). You can directly call fs.mkdir, fs.readdir, etc.fs.existsAsync = Binding.fromCallback(fs.exists);fs.mkdirAsync = Binding.fromStandard(fs.mkdir);fs.readdirAsync = Binding.fromStandard(fs.readdir);fs.statAsync = Binding.fromStandard(fs.stat);fs.closeAsync = Binding.fromStandard(fs.close);fs.openAsync = Binding.fromStandard(fs.open);fs.readAsync = Binding.fromStandard(fs.read);fs.writeAsync = Binding.fromStandard(fs.write);