Daniel Werner has uploaded a new change for review.

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


Change subject: redirect wb.utilities.inherit to dv.util.inherit
......................................................................

redirect wb.utilities.inherit to dv.util.inherit

This redundant code should have been removed a while ago when the code moved 
into the DataValues
extension. Also removed tests since they are in the datavalues extension 
already.

Change-Id: I3977444dcdd5cac7654a98d7d97652827f035524
---
M lib/WikibaseLib.hooks.php
M lib/resources/wikibase.utilities/wikibase.utilities.js
D lib/tests/qunit/wikibase.utilities/wikibase.utilities.inherit.tests.js
3 files changed, 8 insertions(+), 182 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/05/50005/1

diff --git a/lib/WikibaseLib.hooks.php b/lib/WikibaseLib.hooks.php
index f5bd65d..75d19ed 100644
--- a/lib/WikibaseLib.hooks.php
+++ b/lib/WikibaseLib.hooks.php
@@ -153,7 +153,6 @@
                                
'tests/qunit/wikibase.ui.Toolbar.Button.tests.js',
                                'tests/qunit/wikibase.ui.Tooltip.tests.js',
 
-                               
'tests/qunit/wikibase.utilities/wikibase.utilities.inherit.tests.js',
                                
'tests/qunit/wikibase.utilities/wikibase.utilities.newExtension.tests.js',
                                
'tests/qunit/wikibase.utilities/wikibase.utilities.ObservableObject.tests.js',
                                
'tests/qunit/wikibase.utilities/wikibase.utilities.ui.StatableObject.tests.js',
diff --git a/lib/resources/wikibase.utilities/wikibase.utilities.js 
b/lib/resources/wikibase.utilities/wikibase.utilities.js
index 620b7aa..c677821 100644
--- a/lib/resources/wikibase.utilities/wikibase.utilities.js
+++ b/lib/resources/wikibase.utilities/wikibase.utilities.js
@@ -9,7 +9,7 @@
  * @licence GNU GPL v2+
  * @author Daniel Werner
  */
-( function( mw, wb, $, undefined ) {
+( function( mw, wb, dv, $, undefined ) {
        'use strict';
 
        /**
@@ -19,36 +19,14 @@
        wb.utilities = wb.utilities || {};
 
        /**
-        * Helper for prototypal inheritance.
-        *
-        * @param Function base constructor will be used for the prototype chain
-        * @param Function constructor (optional) for overwriting base 
constructor. Can be omitted.
-        * @param Object members (optional) properties overwriting or extending 
those of the base
-        * @return Function the constructor for the new, extended type
+        * @see dataValues.util.inherit
         */
-       wb.utilities.inherit = function( base, constructor, members ) {
-               // allow to omit constructor since it can be inherited 
directly. But if given, require it as second parameter
-               // for readability. If no constructor, second parameter is the 
prototype extension object.
-               if( members === undefined ) {
-                       if( $.isFunction( constructor ) ) {
-                               members = {};
-                       } else {
-                               members = constructor || {}; // also support 
case where no parameters but base are given
-                               constructor = false;
-                       }
-               }
-               var NewConstructor = constructor || function() { base.apply( 
this, arguments ); };
+       wb.utilities.inherit = dv.util.inherit;
 
-               var NewPrototype = function(){}; // new constructor for 
avoiding base constructor and with it any side-effects
-               NewPrototype.prototype = base.prototype;
-
-               NewConstructor.prototype = $.extend(
-                       new NewPrototype(),
-                       { constructor: NewConstructor }, // make sure 
constructor property is set properly, can be overwritten from members
-                       members
-               );
-               return NewConstructor;
-       };
+       /**
+        * @see dv.util.abstractMember
+        */
+       wb.utilities.abstractFunction = dv.util.abstractMember;
 
        /**
         * Can be used to create an empty constructor which can be used to 
create a new Object and at the same time has a
@@ -97,19 +75,4 @@
                return Ext;
        };
 
-       /**
-        * Can be used within wb.utilities.newExtension() declarations or 
elsewhere to throw a more meaningful error
-        * whenever the function should be overwritten (because it acts as an 
interface to the extension) but was not.
-        * @throw Error
-        *
-        * @example:
-        * SomeExt = wb.utilities.newExtension( {
-        *     someFunc: function( a, b ) { ... someAbstractFunc() ... },
-        *     someAbstractFunc: wb.utilities.abstractFunction // required by 
other functions of this extension
-        * } );
-        */
-       wb.utilities.abstractFunction = function() {
-               throw new Error( 'Call to undefined abstract function' );
-       };
-
-}( mediaWiki, wikibase, jQuery ) );
+}( mediaWiki, wikibase, dataValues, jQuery ) );
diff --git 
a/lib/tests/qunit/wikibase.utilities/wikibase.utilities.inherit.tests.js 
b/lib/tests/qunit/wikibase.utilities/wikibase.utilities.inherit.tests.js
deleted file mode 100644
index 6ad6f91..0000000
--- a/lib/tests/qunit/wikibase.utilities/wikibase.utilities.inherit.tests.js
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * QUnit tests for Wikibase inherit() function for more prototypal inheritance 
convenience.
- * @see https://www.mediawiki.org/wiki/Extension:Wikibase
- *
- * @since 0.1
- * @file
- * @ingroup WikibaseLib
- *
- * @licence GNU GPL v2+
- * @author Daniel Werner
- */
-( function( mw, wb, $, QUnit ) {
-       'use strict';
-
-       QUnit.module( 'wikibase.utilities.inherit', QUnit.newWbEnvironment( {
-               setup: function() {},
-               teardown: function() {}
-       } ) );
-
-       // ============================
-       // ======= Test Utils: ========
-       // ============================
-
-var // the following are a couple of var definitions used by the tests beyond
-       /**
-        * Takes three parameters which match the three parameters of the 
inherit() function. If one should be
-        * omitted, null should be given.
-        *
-        * @param base Function
-        * @param constructor Function|null
-        * @param members Object|null
-        */
-       inheritTest = function( base, constructor, members ) {
-               var c;
-               if( constructor === null && members === null ) {
-                       // only base is given:
-                       c = wb.utilities.inherit( base );
-               }
-               else if( constructor === null ) {
-                       // constructor omitted, check for right param mapping:
-                       c =      wb.utilities.inherit( base, members );
-                       var c2 = wb.utilities.inherit( base, 
c.prototype.constructor, members );
-
-                       assert.deepEqual(
-                               c.prototype,
-                               c2.prototype,
-                               'inherit() works as expected if "constructor" 
parameter was omitted.'
-                       );
-                       c2 = null;
-               }
-               else if( members === null ) {
-                       c = wb.utilities.inherit( base, constructor );
-               }
-               else {
-                       c = wb.utilities.inherit( base, constructor, members );
-               }
-
-               assert.ok(
-                       $.isFunction( c ),
-                       'inherit() returned constructor'
-               );
-
-               assert.ok(
-                       ( new c() ) instanceof base && ( new c() ) instanceof c,
-                       '"instanceof" is working like it should'
-               );
-
-               if( constructor !== null ) {
-                       assert.equal(
-                               c,
-                               constructor,
-                               'prototypes constructor property is set to 
given constructor'
-                       );
-               }
-
-               var proto = $.extend( {}, c.prototype );
-               if( members === null || !members.hasOwnProperty( 'constructor' 
) ) {
-                       delete( proto.constructor ); // constructor is an extra 
thing, set by inherit()
-               }
-               if( members !== null ) {
-                       assert.deepEqual(
-                               proto,
-                               ( members !== null ? members : {} ),
-                               'Prototype of returned constructor has all 
extension properties set'
-                       );
-               }
-               return c;
-       },
-
-       inheritMembers = {
-               i: 0,
-               increase: function() { this.i++; },
-               foo: 'baa'
-       },
-
-       inheritConstructor = function() { this.foo = 'test'},
-
-       inheritConstructorTest = function( constructor ) {
-               assert.ok(
-                       ( new constructor() ).foo === 'test',
-                       'Overwritten constructor is called'
-               );
-       };
-
-
-       // ==============================
-       // ======= Actual Tests: ========
-       // ==============================
-
-       QUnit.test( 'inherit( base )', function( assert ) {
-               // members only:
-               inheritTest( Object, null, null );
-       } );
-
-       QUnit.test( 'inherit( base, members )', function( assert ) {
-               // members only:
-               inheritTest( Object, null, inheritMembers );
-       } );
-
-       QUnit.test( 'inherit( base, constructor )', function( assert ) {
-               // constructor only:
-               var c1 = inheritTest( Object, inheritConstructor, null );
-               inheritConstructorTest( c1 );
-
-               // inherit from c2:
-               var c2 = inheritTest( c1, null, inheritMembers );
-               inheritConstructorTest( c2 );
-       } );
-
-       QUnit.test( 'inherit( base, constructor, members )', function( assert ) 
{
-               // both:
-               var c = inheritTest( Object, inheritConstructor, inheritMembers 
);
-               inheritConstructorTest( c );
-       } );
-
-}( mediaWiki, wikibase, jQuery, QUnit ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3977444dcdd5cac7654a98d7d97652827f035524
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <daniel.wer...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to