Class Index | File Index

Classes


Class comb.plugins.Middleware

Plugin to enable middleware on a class
Defined in: Middleware.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
 
_hook(state, op, args)

Protected!

Call to initiate middleware for the topic

NOTE: this function takes a variable number of arguments whatever comes after the op param will be passed into the listening function, with the last argument to the listenting function being the next function

 
post(fun, callback)

Use to listen to after an event has occurred i.e.

<static>  
comb.plugins.Middleware.post(name, cb)

Use to listen to after an event has occurred i.e.

<static>  
comb.plugins.Middleware.pre(name, cb)

Use to listen to after an event has occurred i.e.

 
pre(fun, callback)
Use to listen to before an event occurred i.e.
Class Detail
comb.plugins.Middleware()
var Mammal = define(comb.plugins.Middleware, {
 instance : {

   constructor: function(options) {
       options = options || {};
       this.super(arguments);
       this._type = options.type || "mammal";
   },

   speak : function() {
       var ret = new comb.Promise();
       this._hook("pre", "speak")
               .then(comb.hitch(this, "_hook", "post", "speak"), hitch(ret, "errback"))
               .then(comb.hitch(ret, "callback"), comb.hitch(ret, "errback"));
       return ret;
   }
 }
});

 Mammal.pre('speak', function(next){
    //do something meaningful
    next();
 });
 var m = new Mammal({color : "gold"});
 m.speak();
Method Detail
{comb.Promise} _hook(state, op, args)

Protected!

Call to initiate middleware for the topic

NOTE: this function takes a variable number of arguments whatever comes after the op param will be passed into the listening function, with the last argument to the listenting function being the next function

Parameters:
{"pre"|"post"} state
the state in which the hook should be called
{String} op
the operation that is being acted upong
args
arguments to be passed into the listening functions.
Returns:
{comb.Promise} a promise to use after middleware chain completes

post(fun, callback)

Use to listen to after an event has occurred i.e. post save

NOTE:
instance.post("save", function(next){
               //do something...
                //you have to call next!!!!!
                next();
         });
Parameters:
fun
callback

<static> comb.plugins.Middleware.post(name, cb)

Use to listen to after an event has occurred i.e. post save

NOTE:
Class.post("save", function(next){
              ...
              //you must call next
         });
Parameters:
name
cb

<static> comb.plugins.Middleware.pre(name, cb)

Use to listen to after an event has occurred i.e. post save

NOTE:
Class.pre("save", function(next){
              ...
              //you must call next
         });
Parameters:
name
cb

pre(fun, callback)
Use to listen to before an event occurred i.e. pre save NOTE:
     instance.pre("save", function(args,...., next){
         //do something...
         //you have to call next!!!!!
         next();
     });
Parameters:
fun
callback

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Nov 18 2011 01:10:53 GMT-0600 (CST)