Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/155593

Change subject: [WIP] Replace Mantle's EventEmitter with oojs's
......................................................................

[WIP] Replace Mantle's EventEmitter with oojs's

Change-Id: I960592a3e8f3c853ee676fc6e983beda1b39563e
---
M includes/Resources.php
M javascripts/common/eventemitter.js
2 files changed, 9 insertions(+), 64 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Mantle 
refs/changes/93/155593/1

diff --git a/includes/Resources.php b/includes/Resources.php
index 16548c7..ec189ef 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -67,6 +67,7 @@
        'ext.mantle.oo' => $wgMantleResourceBoilerplate + array(
                'dependencies' => array(
                        'ext.mantle.modules',
+                       'oojs'
                ),
                'scripts' => array(
                        'javascripts/common/Class.js',
diff --git a/javascripts/common/eventemitter.js 
b/javascripts/common/eventemitter.js
index 9e7f37e..fe368fc 100644
--- a/javascripts/common/eventemitter.js
+++ b/javascripts/common/eventemitter.js
@@ -2,70 +2,14 @@
 
        var Class = M.require( 'Class' ), EventEmitter;
 
-       function callbackProxy( callback ) {
-               return function() {
-                       var args = Array.prototype.slice.call( arguments, 1 );
-                       callback.apply( callback, args );
-               };
-       }
-
-       /**
-        * @class
-        * @extends Class
-        */
-       EventEmitter = Class.extend( {
-               /**
-                * Bind a callback to the event.
-                *
-                * @method
-                * @param {string} event Event name.
-                * @param {Function} callback Callback to be bound.
-                */
-               on: function( event, callback ) {
-                       $( this ).on( event, callbackProxy( callback ) );
-                       return this;
-               },
-
-               /**
-                * Bind a callback to the event and run it only once.
-                *
-                * @method
-                * @param {string} event Event name.
-                * @param {Function} callback Callback to be bound.
-                */
-               one: function( event, callback ) {
-                       $( this ).one( event, callbackProxy( callback ) );
-                       return this;
-               },
-
-               /**
-                * Emit an event. This causes all bound callbacks to be run.
-                *
-                * @method
-                * @param {string} event Event name.
-                * @param {*} [arguments] Optional arguments to be passed to 
callbacks.
-                */
-               emit: function( event /* , arg1, arg2, ... */ ) {
-                       var args = Array.prototype.slice.call( arguments, 1 );
-                       // use .triggerHandler() for emitting events to avoid 
accidentally
-                       // invoking object's functions, e.g. don't call 
obj.something() when
-                       // doing obj.emit( 'something' )
-                       $( this ).triggerHandler( event, args );
-                       return this;
-               },
-
-               /**
-                * Remove a callback.
-                *
-                * @name EventEmitter.prototype.off
-                * @method
-                * @param {string} event Event name.
-                */
-               off: function( event ) {
-                       $( this ).off( event );
-                       return this;
-               }
-       } );
+       // HACK: wrap around oojs's EventEmitter
+       // This needs some hackery to make oojs's
+       // and Mantle's different OO models get along,
+       // and we need to alias one() to once().
+       EventEmitter = Class.extend( $.extend( {
+               initialize: OO.EventEmitter,
+               one: OO.EventEmitter.prototype.once
+       }, OO.EventEmitter.prototype ) );
 
        M.define( 'eventemitter', EventEmitter );
        // FIXME: if we want more of M's functionality in loaded in <head>,

-- 
To view, visit https://gerrit.wikimedia.org/r/155593
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I960592a3e8f3c853ee676fc6e983beda1b39563e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Mantle
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to