Follows-up
a8eba66. Use the Promise for the data as well instead of
just as a callback to evaluate a static variable. This removes any
risk of race conditions or other misuse of the variable.
Also simplify the array creation by using map instead of pushing
in an each loop.
Change-Id: Ide1489a5139ef3b26cf0de6ca6f2e675ef32c724
*/
( function ( $, mw ) {
*/
( function ( $, mw ) {
- var interwikiPrefixes = [],
- interwikiPrefixesPromise = new mw.Api().get( {
+ var interwikiPrefixesPromise = new mw.Api().get( {
action: 'query',
meta: 'siteinfo',
siprop: 'interwikimap'
action: 'query',
meta: 'siteinfo',
siprop: 'interwikimap'
- } ).done( function ( data ) {
- $.each( data.query.interwikimap, function ( index, interwiki ) {
- interwikiPrefixes.push( interwiki.prefix );
+ } ).then( function ( data ) {
+ return $.map( data.query.interwikimap, function ( interwiki ) {
+ return interwiki.prefix;
} };
if ( mw.Title.newFromText( query ) ) {
} };
if ( mw.Title.newFromText( query ) ) {
- return interwikiPrefixesPromise.then( function () {
+ return interwikiPrefixesPromise.then( function ( interwikiPrefixes ) {
var params,
interwiki = query.substring( 0, query.indexOf( ':' ) );
if (
var params,
interwiki = query.substring( 0, query.indexOf( ':' ) );
if (