listen.js
/* exactly like send() except that if the current val of obj.attr is a function, it will be called with 
      the sent value, a very common pattern. */
exactly like send() except that if the current val of obj.attr is a function, it will be called with
the sent value, a very common pattern.
exactly like send () except that if the current val of obj . attr is a function it will be called with the sent value a very common pattern .
function fire(obj, attr, val){ 
    var args = Array();
    for(var i = 0; i < arguments.length ; i ++)
        args.push(arguments[i]);
    args = args.slice(2);
    var retval;
    if(typed(obj[attr], Function))
        retval = obj[attr].apply(obj, args);
    if(retval === false)
        return false;
    if(!obj.__listeners__ || !obj.__listeners__[attr])
        return retval;
    var regAttrs = obj.__listeners__[attr];
    var to_run = [];   
    for(var i = 0; i < regAttrs.length; i ++)
        to_run.push([regAttrs[i][0], regAttrs[i][1]]);
    if(args.length === 0){
        for(var i = 0; i < to_run.length; i ++)
            if(to_run[i][0])
                to_run[i][0].call(to_run[i][1] ? to_run[i][1] : obj, val, obj, attr);
    }
    else{
        for(var i = 0; i < to_run.length; i ++)
            if(to_run[i][0])
                to_run[i][0].apply(to_run[i][1] ? to_run[i][1] : obj, args);
    }  
    return retval; 
}
function fire ( obj , attr , val ) { var args = Array ( ) ; for ( var i = 0 ; i < arguments . length ; i ++ ) args . push ( arguments [ i ] ) ; args = args . slice ( 2 ) ; var retval ; if ( typed ( obj [ attr ] , Function ) ) retval = obj [ attr ] . apply ( obj , args ) ; if ( retval === false ) return false ; if ( ! obj . __listeners__ || ! obj . __listeners__ [ attr ] ) return retval ; var regAttrs = obj . __listeners__ [ attr ] ; var to_run = [ ] ; for ( var i = 0 ; i < regAttrs . length ; i ++ ) to_run . push ( [ regAttrs [ i ] [ 0 ] , regAttrs [ i ] [ 1 ] ] ) ; if ( args . length === 0 ) { for ( var i = 0 ; i < to_run . length ; i ++ ) if ( to_run [ i ] [ 0 ] ) to_run [ i ] [ 0 ] . call ( to_run [ i ] [ 1 ] ? to_run [ i ] [ 1 ] : obj , val , obj , attr ) ; } else { for ( var i = 0 ; i < to_run . length ; i ++ ) if ( to_run [ i ] [ 0 ] ) to_run [ i ] [ 0 ] . apply ( to_run [ i ] [ 1 ] ? to_run [ i ] [ 1 ] : obj , args ) ; } return retval ; }
exactly like send() except that if the current val of obj.attr is a function, it will be called with
the sent value, a very common pattern.
exactly like send () except that if the current val of obj . attr is a function it will be called with the sent value a very common pattern .
/* we look at the raw arguments coming in 
       to decide if we've been given one or more then
       one value, and so to either .call or .apply this
       value(s) below */ /* determine if we have args to use or not. is either
       the list of arguments to send or false */ /* if a function exists of that name run it. if it returns false, return that and DONT do any sends  */ /* if there are no listeners, just return the retval. */ /* get a reference to the listeners list */ /* it is CRUCIALLY important to the listening algorithm that one cache the entries to 
       call BEFORE calling them in sequence, as they may alter this list during their execution 
       and while we want that, it means we must rely on a second list to iterate over everything
       correctly! */ /* if we are not applying the value, call the method with a single argument */ /* if we ARE being told to apply the value (via the applyValFlag), we will use
       the list-val as the arguments to use in an .apply call. */