Skip to content

Commit

Permalink
Actions can now be a constructed object rather than a literal.
Browse files Browse the repository at this point in the history
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
pygy committed Dec 11, 2012
1 parent b98a7cf commit 821690c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/request/responders/rpc/request.coffee
Expand Up @@ -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)
Expand Down

0 comments on commit 821690c

Please sign in to comment.