-
Notifications
You must be signed in to change notification settings - Fork 282
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
RPC Actions can now be an object created with new
rather than a literal.
#407
Conversation
Cool idea! 👍 |
Hi, thanks for submitting this. I'll take a look at it later today. |
My concern is: function RPC(req,res,ss){
this.req = req;
this.res = res;
this.ss = ss;
} It's kinda annoying to put it in each file within |
You need one per API, since you attach the methods to the prototype. // store this wherever relevant...
function factory (actions) { // I'm sure there's a better name :-)
var RPC = function (req,res,ss){
this.req = req;
this.res = res;
this.ss = ss;
}
RPC.prototype = actions
return RPC
} Then, in RPC = factory({
sendMessage: function(message) {
// ...
}
}) |
RPC Actions can now be an object created with `new` rather than a literal.
Thanks. At some point we'll want to document this in the guide, and give a description of the pros/cons |
This sounds very interesting. Code snippet of example usage possibility? On Thu, Oct 24, 2013 at 1:54 AM, Paul Jensen notifications@github.comwrote:
|
It's all in the first post. Contrast with |
BTW, thanks for accepting this :-) |
You're welcome, thanks for contributing it, there's always room for On 25 October 2013 16:41, pygy notifications@github.com wrote:
Paul Jensen |
Hi guys, I still think that we need to add code from #407 (comment) to SocketStream api.add('rcpProvider', function(){
...
});
}; Still kind of ugly, but i think since SS is a framework it should not be up to user, too complicated =) ...or maye should be something like following inside var ss = require('socketstream');
ss.use('rcpProvider'); Thoughts? |
I don't know where to put this either, since files in API are not supposed to require SocketStream. The Maybe you could put it as a small helper file, either in |
This is a revival of #327, now that Paul is at the helm I hope it can be revisited.
This tiny patch allows to use objects created with
new
as RPC handlers, rather than object literals with closures. It removes pressure from the allocator/garbage collector, since otherwise, closures have to be created for each requests, most of which are not used anyway.The resulting code is a bit uglier but much more efficient, especially for large RPC APIs.
Example (revisiting the "new_project" sample):
The old method can still be used for all practical use cases.
The patch may theoretically break code that relies on the fact that, without the patch,
this
in a handler is the handler itself. I can't see anyone sane rely on that.