Class Index | File Index

## Classes

- _global_
- comb
- comb.array
- comb.characters
- comb.collections
- comb.collections.AnderssonTree
- comb.collections.AVLTree
- comb.collections.BinaryTree
- comb.collections.Collection
- comb.collections.HashTable
- comb.collections.Heap
- comb.collections.Iterable
- comb.collections.MaxHeap
- comb.collections.MinHeap
- comb.collections.Pool
- comb.collections.PriorityQueue
- comb.collections.Queue
- comb.collections.RedBlackTree
- comb.collections.Stack
- comb.collections.Tree
- comb.date
- comb.logging
- comb.logging.appenders
- comb.logging.appenders.Appender
- comb.logging.appenders.ConsoleAppender
- comb.logging.appenders.FileAppender
- comb.logging.appenders.JSONAppender
- comb.logging.appenders.RollingFileAppender
- comb.logging.BasicConfigurator
- comb.logging.Level
- comb.logging.Logger
- comb.logging.PropertyConfigurator
- comb.number
- comb.plugins
- comb.plugins.Broadcaster
- comb.plugins.Middleware
- comb.Promise
- comb.PromiseList
- comb.regexp
- comb.string

# Class comb.plugins.Middleware

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

Class Summary
Constructor Attributes | Constructor Name and Description
--- | ---
| comb.plugins.Middleware()

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:

- You must call next in order for the middleware chain to complete
- This connects to events on the instance of an object, NOT all instances!
- Hooks are called in the order they are received!
- When connecting your callback will be called in the scope of the classif you want a certain scope use comb.hitch

    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:

- You must call next in order for the middleware chain to complete
- This connects to events on ALL instances of an object
- Hooks are called in the order they are received!
- When connecting your callback will be called in the scope of the classif you want a certain scope use comb.hitch

    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:

- You must call next in order for the middleware chain to complete
- This connects to events on ALL instances of an object
- Hooks are called in the order they are received!
- When connecting your callback will be called in the scope of the classif you want a certain scope use comb.hitch

    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:

- You must call next in order for the middleware chain to complete
- This connects to events on the instance of an object, not all instances!
- Hooks are called in the order they are received!
- When connecting your callback will be called in the scope of the classif you want a certain scope use comb.hitch

         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 Tue Oct 25 2011 13:20:07 GMT-0500 (CDT)