-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make hprose aware of CommonJS #4
Comments
CommonJS is very useful on:
But hprose-js can only work on browser-applications, it can't work on server-side. hprose-nodejs is a node.js (CommonJS) module, it can work on everywhere except browser. hprose-html5 is another hprose implementation for browser-applications, and it also can work on Hybrid applications (Titanium, Adobe AIR, cocos2d-js jsb applications). I added requirejs and seajs support for this version. I think to add requirejs and seajs support for hprose-js is more useful than making hprose-js aware of CommonJS. Do you think so? Best regards, |
RequireJS - which basically is CommonJS - is becoming very, very popular these days. In fact, jQuery, for instance, handles both styles, AMD and CommonJS at once, and allows to be ran inside NodeJS if a What I would suggest for hprose-js is that it implements at least CommonJS. It gives developers the option to smoothly move their code to another platform without losing much features or having a big burden of converting their code. Actually I don't know what the difference between hprose-js and hprose-html5 is. It looks very similar from a short glance. So my opinion is, that you should add RequireJS support, since that is pretty much CommonJS. Here is a little template that can maybe help you with getting this going: (function(root, construct){
if(typeof module != "undefined" && typeof exports == "object") {
module.exports = construct();
} else {
root.hprose = construct();
}
})(this, function(){
// hprose code goes here. Here is an example:
var hprose = {};
hprose.foo = function() {}
return hprose;
// A module that require()'d this file now gets the hprose object.
}); Kind regards, Ingwie. |
hprose-js and hprose-html5 have different API interface, because we want they can work together without conflict. The significance of the existence of hprose-js is only in order to be compatible with old browsers. hprose-nodejs is compatible with the above two kinds of API interface. so if the developers want to move the hprose-js or hprose-html5 application to another platform, they don't need to converting any code, only to change the hprose-js or hprose-html5 to hprose-nodejs. and there is no feature losing, instead, they will get more features. jQuery need to handle AMD and CommonJS at once, because it only have one implementation. Hprose don't need to handle AMD and CommonJS at once, because hprose have three implementation. But I can add CommonJS support to hprose-html5, because it is easy to do and more useful than hprose-js. Best regards, |
Oh I see! So if hprose-js is ment for older browsers, then I am likely better off when using hprose-html5. In the long run, you should consider if it maybe isnt easier to merge the two together instead of maintaining two similar, but not similar, projects at the same time. For now, I'd suggest adding the CommonJS/AMD support since many people seem to use it. One great usage is WebPack which I am successfuly using in my BIRD3 project - it makes many things much easier. |
I will add CommonJS support for hprose-html5, tonight. |
Awesome! I can then work with hprose in my app also in client side. :)
By the way, what is this Future-async stuff about?
|
Completer/Future async is come from dart language. It is very similar to Promises/A+. But I simplify its implementation. I only reserved the following methods and properties:
for example: var completer = new Completer();
var client = new hprose.Client.create('http://hprose.com/example/');
client.then(function(stub) {
stub.hello('World')
.then(function(result) {
completer.complete(result);
})
.catchError(function(e) {
completer.completeError(e);
})
})
.catchError(function(e) {
console.error(e);
})
...
var future = completer.future;
future.then(function(result) {
console.info(result);
})
.catchError(function(e) {
console.error(e);
}) and I will add this feature in PHP, too, with this feature, we can publish an async service. |
I already have added CommonJS support for hprose-html5, just now. |
hprose for javascript is update.
|
Awesome, thanks for the update! :)
|
I am planning on writing an RPC layer that is capable of running on "almost" all frameworks. In order to properly support this, hprose-js needs to learn to export. This is simple. As you know NodeJS, this will look very familiar to you:
The idea is, to have hprose initialize on a local variable first (
hprose
in my case). Then we can do something like jQuery does here: https://github.com/jquery/jquery/blob/2.1.4/dist/jquery.js#L15-L38Do you think this is possible?
Kind regards,
Ingwie
The text was updated successfully, but these errors were encountered: