Ori.livneh has uploaded a new change for review.

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

Change subject: mw.Map#get: accept an object selection
......................................................................

mw.Map#get: accept an object selection

There is a familiar JavaScript idiom in the MediaWiki ecosystem for
representing the page context as a plain object that maps human-readable
property names to configuration variables. A small modification to mw.Map#get
makes it more concise and nicer to read and to type.

Current idiom:

    var pageContext = {
        pageId  : mw.config.get( 'wgArticleId' ),
        revId   : mw.config.get( 'wgCurRevisionId' ),
        version : mw.config.get( 'wgVersion' )
    };

Proposed:

    var pageContext = mw.config.get( {
        pageId  : 'wgArticleId',
        revId   : 'wgCurRevisionId',
        version : 'wgVersion'
    } );

Change-Id: I74b91d98493df2ba75312143ed38313852ef3575
---
M resources/src/mediawiki/mediawiki.js
1 file changed, 15 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/66/192766/1

diff --git a/resources/src/mediawiki/mediawiki.js 
b/resources/src/mediawiki/mediawiki.js
index 2e78c1c..ee207ff 100644
--- a/resources/src/mediawiki/mediawiki.js
+++ b/resources/src/mediawiki/mediawiki.js
@@ -142,29 +142,27 @@
                 *  as is the default in JavaScript, the object is returned by 
reference.)
                 */
                get: function ( selection, fallback ) {
-                       var results, i;
+                       var that = this, results = {}, type = $.type( selection 
);
+
                        // If we only do this in the `return` block, it'll fail 
for the
                        // call to get() from the mutli-selection block.
                        fallback = arguments.length > 1 ? fallback : null;
 
-                       if ( $.isArray( selection ) ) {
-                               selection = slice.call( selection );
-                               results = {};
-                               for ( i = 0; i < selection.length; i++ ) {
-                                       results[selection[i]] = this.get( 
selection[i], fallback );
-                               }
-                               return results;
-                       }
+                       switch ( type ) {
+                       case 'string':
+                               return hasOwn.call( this.values, selection ) ?
+                                       this.values[selection] : fallback;
 
-                       if ( typeof selection === 'string' ) {
-                               if ( !hasOwn.call( this.values, selection ) ) {
-                                       return fallback;
-                               }
-                               return this.values[selection];
-                       }
-
-                       if ( selection === undefined ) {
+                       case 'undefined':
                                return this.values;
+
+                       case 'array':
+                       case 'object':
+                               $.each( selection, function ( index, key ) {
+                                       index = typeof index === 'number' ? key 
: index;
+                                       results[index] = that.get( key, 
fallback );
+                               } );
+                               return results;
                        }
 
                        // Invalid selection key

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I74b91d98493df2ba75312143ed38313852ef3575
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

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

Reply via email to