src/basis/event.js
function createDispatcher(eventName){
    var eventFunction = events[eventName];

    if (!eventFunction)
    {
      eventFunction = function(){
        var cursor = this;
        var args;
        var fn;

        while (cursor = cursor.handler)
        {
          // callback call
          fn = cursor.callbacks[eventName];
          if (typeof fn == 'function')
          {
            if (!args)
            {
              // it should be better for browser optimizations
              // (instead of [this].concat(slice.call(arguments)))
              args = [this];
              for (var i = 0; i < arguments.length; i++)
                args.push(arguments[i]);
            }

            fn.apply(cursor.context || this, args);
          }

          // any event callback call
          fn = cursor.callbacks['*'];
          if (typeof fn == 'function')
          {
            if (!args)
            {
              // it should be better for browser optimizations
              // (instead of [this].concat(slice.call(arguments)))
              args = [this];
              for (var i = 0; i < arguments.length; i++)
                args.push(arguments[i]);
            }

            fn.call(cursor.context || this, {
              sender: this,
              type: eventName,
              args: args
            });
          }
        }

        // feature available in development mode only
        /** @cut */ if (this.debug_emit)
        /** @cut */ {
        /** @cut */   args = [];  // avoid optimization warnings about arguments
        /** @cut */   for (var i = 0; i < arguments.length; i++)
        /** @cut */     args.push(arguments[i]);
        /** @cut */   this.debug_emit({
        /** @cut */     sender: this,
        /** @cut */     type: eventName,
        /** @cut */     args: args
        /** @cut */   });
        /** @cut */ }
      };

      // function wrapper for more verbose in development mode
      /** @cut */ eventFunction = new Function(
      /** @cut */   'return {"' + namespace + '.events.' + eventName + '":\n\n      ' +
      /** @cut */
      /** @cut */     'function(' + basis.array(arguments, 1).join(', ') + '){' +
      /** @cut */       eventFunction.toString()
      /** @cut */         .replace(/\beventName\b/g, '"' + eventName + '"')
      /** @cut */         .replace(/^function[^(]*\(\)[^{]*\{|\}$/g, '') +
      /** @cut */     '}' +
      /** @cut */
      /** @cut */   '\n\n}["' + namespace + '.events.' + eventName + '"];'
      /** @cut */ )();

      events[eventName] = eventFunction;
    }

    return eventFunction;
  }
function createDispatcher(eventName){
    var eventFunction = events[eventName];

    if (!eventFunction)
    {
      eventFunction = function(){
        var cursor = this;
        var args;
        var fn;

        while (cursor = cursor.handler)
        {
          // callback call
          fn = cursor.callbacks[eventName];
          if (typeof fn == 'function')
          {
            if (!args)
            {
              // it should be better for browser optimizations
              // (instead of [this].concat(slice.call(arguments)))
              args = [this];
              for (var i = 0; i < arguments.length; i++)
                args.push(arguments[i]);
            }

            fn.apply(cursor.context || this, args);
          }

          // any event callback call
          fn = cursor.callbacks['*'];
          if (typeof fn == 'function')
          {
            if (!args)
            {
              // it should be better for browser optimizations
              // (instead of [this].concat(slice.call(arguments)))
              args = [this];
              for (var i = 0; i < arguments.length; i++)
                args.push(arguments[i]);
            }

            fn.call(cursor.context || this, {
              sender: this,
              type: eventName,
              args: args
            });
          }
        }

        // feature available in development mode only
        /** @cut */ if (this.debug_emit)
        /** @cut */ {
        /** @cut */   args = [];  // avoid optimization warnings about arguments
        /** @cut */   for (var i = 0; i < arguments.length; i++)
        /** @cut */     args.push(arguments[i]);
        /** @cut */   this.debug_emit({
        /** @cut */     sender: this,
        /** @cut */     type: eventName,
        /** @cut */     args: args
        /** @cut */   });
        /** @cut */ }
      };

      // function wrapper for more verbose in development mode
      /** @cut */ eventFunction = new Function(
      /** @cut */   'return {"' + namespace + '.events.' + eventName + '":\n\n      ' +
      /** @cut */
      /** @cut */     'function(' + basis.array(arguments, 1).join(', ') + '){' +
      /** @cut */       eventFunction.toString()
      /** @cut */         .replace(/\beventName\b/g, '"' + eventName + '"')
      /** @cut */         .replace(/^function[^(]*\(\)[^{]*\{|\}$/g, '') +
      /** @cut */     '}' +
      /** @cut */
      /** @cut */   '\n\n}["' + namespace + '.events.' + eventName + '"];'
      /** @cut */ )();

      events[eventName] = eventFunction;
    }

    return eventFunction;
  }
function createDispatcher ( eventName ) { var eventFunction = events [ eventName ] ; if ( ! eventFunction ) { eventFunction = function ( ) { var cursor = this ; var args ; var fn ; while ( cursor = cursor . handler ) { // callback call fn = cursor . callbacks [ eventName ] ; if ( typeof fn == 'function' ) { if ( ! args ) { // it should be better for browser optimizations // (instead of [this].concat(slice.call(arguments))) args = [ this ] ; for ( var i = 0 ; i < arguments . length ; i ++ ) args . push ( arguments [ i ] ) ; } fn . apply ( cursor . context || this , args ) ; } // any event callback call fn = cursor . callbacks [ '*' ] ; if ( typeof fn == 'function' ) { if ( ! args ) { // it should be better for browser optimizations // (instead of [this].concat(slice.call(arguments))) args = [ this ] ; for ( var i = 0 ; i < arguments . length ; i ++ ) args . push ( arguments [ i ] ) ; } fn . call ( cursor . context || this , { sender : this , type : eventName , args : args } ) ; } } // feature available in development mode only /** @cut */ if ( this . debug_emit ) /** @cut */ { /** @cut */ args = [ ] ; // avoid optimization warnings about arguments /** @cut */ for ( var i = 0 ; i < arguments . length ; i ++ ) /** @cut */ args . push ( arguments [ i ] ) ; /** @cut */ this . debug_emit ( { /** @cut */ sender : this , /** @cut */ type : eventName , /** @cut */ args : args /** @cut */ } ) ; /** @cut */ } } ; // function wrapper for more verbose in development mode /** @cut */ eventFunction = new Function ( /** @cut */ 'return {"' + namespace + '.events.' + eventName + '":\n\n      ' + /** @cut */ /** @cut */ 'function(' + basis . array ( arguments , 1 ) . join ( ', ' ) + '){' + /** @cut */ eventFunction . toString ( ) /** @cut */ . replace ( / \beventName\b / g , '"' + eventName + '"' ) /** @cut */ . replace ( / ^function[^(]*\(\)[^{]*\{|\}$ / g , '' ) + /** @cut */ '}' + /** @cut */ /** @cut */ '\n\n}["' + namespace + '.events.' + eventName + '"];' /** @cut */ ) ( ) ; events [ eventName ] = eventFunction ; } return eventFunction ; }
Creates new type of event or returns existing one, if it was created before.
@param {string} eventName
@return {function(..eventArgs)}
Creates new type of event or returns existing one if it was created before .