Permalink
Browse files

Actions can now be a constructed object rather than a literal.

This is lighter from a memory standpoint, especially for large handlers.

Example:

```
function RPC(req,res,ss){
  this.req = req;
  this.res = res;
  this.ss = ss;
}

RPC.prototype.sendMessage = function(message) {
  if (message && message.length > 0) {          // Check for blank messages
    this.ss.publish.all('newMessage', message);     // Broadcast the message to everyone
    return this.res(true);                          // Confirm it was sent to the originating client
  } else {
    return this.res(false);
  }
}

exports.actions = function(req, res, ss) {
  req.use('session');
  return new RPC(req,res,ss);
};
```
  • Loading branch information...
1 parent b98a7cf commit 821690c342ba4aecfdb36b92b99742cb1aefe2b9 @pygy committed Dec 11, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 src/request/responders/rpc/request.coffee
@@ -68,7 +68,7 @@ module.exports = (ss, middleware) ->
return res(new Error("The '#{req.method}' method in exports.actions must be a function")) unless typeof(method) == 'function'
# Execute action
- method.apply(method, req.params)
+ method.apply(actions, req.params)
# Add RPC call to bottom of middleware stack
stack.push(main)

0 comments on commit 821690c

Please sign in to comment.