https://bugzilla.wikimedia.org/show_bug.cgi?id=23580

Krinkle <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|patch, reviewed             |

--- Comment #13 from Krinkle <[email protected]> 2011-11-09 21:57:51 UTC ---
Using the jQuery Event binding/triggering model doesn't seem good on
performance (kinda slow for something this simple). Also it's not very
recommended by jQuery to use it for this.

I'd suggest we create a simple module ourselves, the functionality we want here
really is simple and we should be able to rely on this.

A very rough example:

  var register = {};

  mw.hooks = {
    register: function( name, callback ) {

      if(!register[name]) register[name] = [];

      push.call( register[name], callback );

    },
    run: function( name [, data ] ) {

      if(!register[name]) return;

      for ( var i = 0, len = register[name].length; i < len; i++ ) {
        register[name][i].apply( data || [] );
      }

    }
  };

If we update our copy of jQuery to 1.7 we could even use jQuery.Callbacks [1]
to make this code a little more robust and shorter. 

--
Krinkle

[1] http://api.jquery.com/jQuery.Callbacks/#pubsub

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to