Jdlrobson has uploaded a new change for review.

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

Change subject: Remove api code that is not used or replicated in core
......................................................................

Remove api code that is not used or replicated in core

We are loading this code when we don't need to. I'm really keen for us
to remove this as it impacts the time for all our users to access features such
as search. Every byte counts.

Bug: T110718
Change-Id: Ibc243a7308c4c2e91c2926fc5c667a774b8404ce
---
M resources/mobile.startup/api.js
D tests/qunit/mobile.startup/test_api.js
2 files changed, 0 insertions(+), 179 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/97/240297/1

diff --git a/resources/mobile.startup/api.js b/resources/mobile.startup/api.js
index 39188d7..4ce8c7b 100644
--- a/resources/mobile.startup/api.js
+++ b/resources/mobile.startup/api.js
@@ -21,102 +21,6 @@
                initialize: function () {
                        mw.Api.apply( this, arguments );
                        EventEmitter.prototype.initialize.apply( this, 
arguments );
-                       this.requests = [];
-                       this.tokenCache = {};
-               },
-
-               /**
-                * A wrapper for $.ajax() to be used when calling server APIs.
-                * Sets URL to API URL and default data type to JSON.
-                * Preprocesses data argument in the following way:
-                * - removes boolean values equal to false
-                * - concatenates Array values with '|'
-                *
-                *     @example
-                *     <code>
-                *     ajax( { a: false, b: [1, 2, 3] }, { type: 'post' } );
-                *     // is equal to
-                *     $.ajax( {
-                *         type: 'post',
-                *         data: { b: '1|2|3' }
-                *     } );
-                *     </code>
-                *
-                * @method
-                * @param {Object} data Data to be preprocessed and added to 
options
-                * @param {Object} options Parameters passed to $.ajax()
-                * @return {jQuery.Deferred} Object returned by $.ajax()
-                */
-               ajax: function ( data, options ) {
-                       var key, request, self = this;
-
-                       options = options || {};
-
-                       if ( typeof data !== 'string' ) {
-                               for ( key in data ) {
-                                       if ( data.hasOwnProperty( key ) ) {
-                                               if ( data[key] === false ) {
-                                                       delete data[key];
-                                               } else if ( $.isArray( 
data[key] ) ) {
-                                                       data[key] = 
data[key].join( '|' );
-                                               }
-                                       }
-                               }
-                       }
-
-                       /**
-                        * This setups support for upload progress events.
-                        * See 
https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#make-upload-progress-notifications
-                        * FIXME: move to mw.Api (although no EventEmitter in 
core)?
-                        * @ignore
-                        * @returns {jqXHR}
-                        */
-                       options.xhr = function () {
-                               var xhr = $.ajaxSettings.xhr();
-                               if ( xhr.upload ) {
-                                       // need to bind this event before we 
open the connection (see note at
-                                       // 
https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress)
-                                       xhr.upload.addEventListener( 
'progress', function ( ev ) {
-                                               if ( ev.lengthComputable ) {
-                                                       /**
-                                                        * @event progress
-                                                        * Fired when a pending 
XHR request fires a progress event.
-                                                        */
-                                                       self.emit( 'progress', 
request, ev.loaded / ev.total );
-                                               }
-                                       } );
-                               }
-                               return xhr;
-                       };
-
-                       request = mw.Api.prototype.ajax.call( this, data, 
options );
-                       this.requests.push( request );
-                       return request;
-               },
-
-               /**
-                * Abort all unfinished requests issued by this Api object.
-                * FIXME: move to mw.Api
-                * @method
-                */
-               abort: function () {
-                       $.each( this.requests, function ( index, request ) {
-                               request.abort();
-                       } );
-               },
-
-               /**
-                * Returns the current URL including protocol
-                *
-                * @method
-                * @return {String}
-                */
-               getOrigin: function () {
-                       var origin = window.location.protocol + '//' + 
window.location.hostname;
-                       if ( window.location.port ) {
-                               origin += ':' + window.location.port;
-                       }
-                       return origin;
                }
        } );
 
diff --git a/tests/qunit/mobile.startup/test_api.js 
b/tests/qunit/mobile.startup/test_api.js
deleted file mode 100644
index bd9cb39..0000000
--- a/tests/qunit/mobile.startup/test_api.js
+++ /dev/null
@@ -1,83 +0,0 @@
-// FIXME: Various tests are skipped as they incorrectly stub inside the test.
-// These stubs should be moved into setup so they do not have side effects on 
other tests.
-( function ( M, $ ) {
-       var Api = M.require( 'mobile.startup/api' ).Api;
-
-       QUnit.module( 'MobileFrontend api', {
-               setup: function () {
-                       var self = this,
-                               server = this.sandbox.useFakeServer();
-                       server.xhr.onCreate = function ( xhr ) {
-                               // FIXME: smelly, sinon.extend and 
sinon.EventTarget are not public interface
-                               xhr.upload = window.sinon.extend( {}, 
window.sinon.EventTarget );
-                               self.lastXhr = xhr;
-                       };
-               }
-       } );
-
-       QUnit.test( 'default instance', 1, function ( assert ) {
-               assert.ok( M.require( 'mobile.startup/api' ) instanceof Api, 
'return default instance' );
-       } );
-
-       QUnit.skip( 'progress event', 1, function ( assert ) {
-               var spy = this.sandbox.spy(),
-                       api = new Api(),
-                       request;
-
-               api.on( 'progress', spy );
-               request = api.post();
-               this.lastXhr.upload.dispatchEvent( {
-                       type: 'progress',
-                       lengthComputable: true,
-                       loaded: 1,
-                       total: 2
-               } );
-               assert.ok( spy.calledWith( request, 0.5 ), 'emit progress 
event' );
-       } );
-
-       QUnit.module( 'MobileFrontend api.Api', {
-               setup: function () {
-                       var self = this,
-                               requests = this.requests = [];
-                       this.api = new Api();
-                       this.sandbox.stub( mw.Api.prototype, 'ajax', function 
() {
-                               var request = $.extend( {
-                                       abort: self.sandbox.spy()
-                               }, $.Deferred() );
-                               requests.push( request );
-                               return request;
-                       } );
-               }
-       } );
-
-       QUnit.test( '#ajax', 1, function ( assert ) {
-               this.api.ajax( {
-                       falseBool: false,
-                       trueBool: true,
-                       list: [ 'one', 2, 'three' ],
-                       normal: 'test'
-               } );
-               assert.ok(
-                       mw.Api.prototype.ajax.calledWithMatch( {
-                               trueBool: true,
-                               list: 'one|2|three',
-                               normal: 'test'
-                       } ),
-                       'set defaults and transform boolean and array data'
-               );
-       } );
-
-       QUnit.test( '#abort', 2, function ( assert ) {
-               this.api.get( {
-                       a: 1
-               } );
-               this.api.post( {
-                       b: 2
-               } );
-               this.api.abort();
-               $.each( this.requests, function ( i, request ) {
-                       assert.ok( request.abort.calledOnce, 'abort request 
number ' + i );
-               } );
-       } );
-
-}( mw.mobileFrontend, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc243a7308c4c2e91c2926fc5c667a774b8404ce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to