Jhernandez has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/345420 )
Change subject: Hygiene: Change $.map to ES5 array.map ...................................................................... Hygiene: Change $.map to ES5 array.map Additional changes: Properly initialize variable as a map when data is a map Change-Id: I3c9788a744971588189faccf1649186793633720 --- M resources/mobile.gallery/PhotoListGateway.js M resources/mobile.nearby/NearbyGateway.js M resources/mobile.search.api/SearchGateway.js M resources/mobile.startup/PageGateway.js M resources/mobile.watchlist/WatchListGateway.js M tests/qunit/mobile.startup/test_browser.js 6 files changed, 20 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/20/345420/1 diff --git a/resources/mobile.gallery/PhotoListGateway.js b/resources/mobile.gallery/PhotoListGateway.js index 7bd107d..be101f2 100644 --- a/resources/mobile.gallery/PhotoListGateway.js +++ b/resources/mobile.gallery/PhotoListGateway.js @@ -111,8 +111,9 @@ var photos; if ( resp.query && resp.query.pages ) { // FIXME: [API] in an ideal world imageData would be a sorted array - photos = $.map( resp.query.pages, function ( page ) { - return self._getImageDataFromPage.call( self, page ); + // but it is a map of {[id]: page} + photos = Object.keys( resp.query.pages ).map( function ( id ) { + return self._getImageDataFromPage.call( self, resp.query.pages[id] ); } ).sort( function ( a, b ) { return a.timestamp < b.timestamp ? 1 : -1; } ); diff --git a/resources/mobile.nearby/NearbyGateway.js b/resources/mobile.nearby/NearbyGateway.js index 1b952e1..85e273d 100644 --- a/resources/mobile.nearby/NearbyGateway.js +++ b/resources/mobile.nearby/NearbyGateway.js @@ -104,13 +104,16 @@ this.api.ajax( requestParams ).then( function ( resp ) { var pages; + + // resp.query.pages is an Array<Page> instead of a map like in other + // API requests if ( resp.query ) { pages = resp.query.pages || []; } else { pages = []; } - pages = $.map( pages, function ( page, i ) { + pages = pages.map( function ( page, i ) { var coords, p; p = Page.newFromJSON( page ); p.anchor = 'item_' + i; diff --git a/resources/mobile.search.api/SearchGateway.js b/resources/mobile.search.api/SearchGateway.js index a1af71c..3405269 100644 --- a/resources/mobile.search.api/SearchGateway.js +++ b/resources/mobile.search.api/SearchGateway.js @@ -108,9 +108,9 @@ if ( data.query ) { - results = data.query.pages || []; - results = $.map( results, function ( result ) { - return self._getPage( query, result ); + results = data.query.pages || {}; + results = Object.keys( results ).map( function ( id ) { + return self._getPage( query, results[ id ] ); } ); // sort in order of index results.sort( function ( a, b ) { diff --git a/resources/mobile.startup/PageGateway.js b/resources/mobile.startup/PageGateway.js index eb1fca7..6f7d0b4 100644 --- a/resources/mobile.startup/PageGateway.js +++ b/resources/mobile.startup/PageGateway.js @@ -38,7 +38,7 @@ */ function transformSections( sections ) { var - collapseLevel = Math.min.apply( this, $.map( sections, function ( s ) { + collapseLevel = Math.min.apply( this, sections.map( function ( s ) { return s.level; } ) ).toString(), lastSection, diff --git a/resources/mobile.watchlist/WatchListGateway.js b/resources/mobile.watchlist/WatchListGateway.js index dc46ec7..c0c3799 100644 --- a/resources/mobile.watchlist/WatchListGateway.js +++ b/resources/mobile.watchlist/WatchListGateway.js @@ -82,8 +82,8 @@ } // Convert the map to an Array. - pages = $.map( data.query.pages, function ( page ) { - return page; + pages = Object.keys( data.query.pages ).map( function ( id ) { + return data.query.pages[ id ]; } ); // Sort results alphabetically (the api map doesn't have any order). The @@ -100,7 +100,7 @@ } // Transform the items to a sensible format - return $.map( pages, function ( item ) { + return pages.map( function ( item ) { return Page.newFromJSON( item ); } ); } diff --git a/tests/qunit/mobile.startup/test_browser.js b/tests/qunit/mobile.startup/test_browser.js index 047fccb..319a731 100644 --- a/tests/qunit/mobile.startup/test_browser.js +++ b/tests/qunit/mobile.startup/test_browser.js @@ -29,11 +29,6 @@ function cache( obj, method ) { return obj[ '__cache' + obj[ method ].cacheId ]; } - function keys( obj ) { - return $.map( obj, function ( key ) { - return key; - } ); - } // Check that the same methods across different instances have their own // cache and don't interfere with one another @@ -49,12 +44,12 @@ // Check that the caches have been filled // NOTE: In the constructor isAndroid2 is called with empty // so account for that on the assertions: - assert.strictEqual( keys( cache( ipad, 'isIos' ) ).length, 2, 'isIos on ipad cached as expected' ); - assert.strictEqual( keys( cache( ipad, 'isAndroid2' ) ).length, 1, 'isAndroid2 on ipad cached as expected' ); - assert.strictEqual( keys( cache( android2, 'isIos' ) ).length, 1, 'isIos on android cached as expected' ); - assert.strictEqual( keys( cache( android2, 'isAndroid2' ) ).length, 1, 'isAndroid2 on android2 cached as expected' ); - assert.strictEqual( keys( cache( iphone, 'isAndroid2' ) ).length, 1, 'isAndroid2 on iphone cached as expected' ); - assert.strictEqual( keys( cache( iphone, 'isIos' ) ).length, 2, 'isIos on iphone cached as expected' ); + assert.strictEqual( Object.keys( cache( ipad, 'isIos' ) ).length, 2, 'isIos on ipad cached as expected' ); + assert.strictEqual( Object.keys( cache( ipad, 'isAndroid2' ) ).length, 1, 'isAndroid2 on ipad cached as expected' ); + assert.strictEqual( Object.keys( cache( android2, 'isIos' ) ).length, 1, 'isIos on android cached as expected' ); + assert.strictEqual( Object.keys( cache( android2, 'isAndroid2' ) ).length, 1, 'isAndroid2 on android2 cached as expected' ); + assert.strictEqual( Object.keys( cache( iphone, 'isAndroid2' ) ).length, 1, 'isAndroid2 on iphone cached as expected' ); + assert.strictEqual( Object.keys( cache( iphone, 'isIos' ) ).length, 2, 'isIos on iphone cached as expected' ); // Mess up the cache and see if the objects return the correct value when // called again with the same arguments -- To view, visit https://gerrit.wikimedia.org/r/345420 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3c9788a744971588189faccf1649186793633720 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jhernandez <jhernan...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits