Giter Site home page Giter Site logo

Comments (10)

IngwiePhoenix avatar IngwiePhoenix commented on May 14, 2024 1

from hprose-js.

andot avatar andot commented on May 14, 2024

CommonJS is very useful on:

  • Server-side JavaScript applications
  • Command line tools
  • Desktop GUI-based applications
  • Hybrid applications (Titanium, Adobe AIR)

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,
Ma Bingyao

from hprose-js.

IngwiePhoenix avatar IngwiePhoenix commented on May 14, 2024

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 window-like object can be specified, so they say.

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.

from hprose-js.

andot avatar andot commented on May 14, 2024
features hprose-js hprose-html5 hprose-nodejs
binary data
browser applications
old browser
cross domain flash & cors cors
http client
tcp client
unix socket client
websocket client
Server-side applications maybe
Command line tools maybe
Desktop GUI-based applications maybe
Hybrid applications (Titanium, Adobe AIR) maybe
http service/server
tcp service/server
unix socket service/server
websocket service/server
Completer/Future async todo
RequireJS(AMD) todo or not
SeaJS(CMD) todo or not
CommonJS
global HproseXXX (such as HproseClient)
hprose.XXX (such as hprose.Client)

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,
Ma Bingyao

from hprose-js.

IngwiePhoenix avatar IngwiePhoenix commented on May 14, 2024

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.

from hprose-js.

andot avatar andot commented on May 14, 2024

I will add CommonJS support for hprose-html5, tonight.

from hprose-js.

IngwiePhoenix avatar IngwiePhoenix commented on May 14, 2024

from hprose-js.

andot avatar andot commented on May 14, 2024

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:

class method
Completer constructor
Completer complete
Completer completeError
Future then
Future catchError
class property
Completer future

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.

from hprose-js.

andot avatar andot commented on May 14, 2024

I already have added CommonJS support for hprose-html5, just now.

from hprose-js.

andot avatar andot commented on May 14, 2024

hprose for javascript is update.

features hprose-js hprose-html5 hprose-nodejs
binary data
browser applications
old browser
cross domain flash & cors cors
http client
tcp client
unix socket client
websocket client
Server-side applications maybe maybe
Command line tools maybe maybe
Desktop GUI-based applications
Hybrid applications (Titanium, Adobe AIR)
http service/server
tcp service/server
unix socket service/server
websocket service/server
Completer/Future async
RequireJS(AMD)
SeaJS(CMD)
CommonJS
global HproseXXX (such as HproseClient)
hprose.XXX (such as hprose.Client)

from hprose-js.

Related Issues (9)

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.