Jdlrobson has uploaded a new change for review.

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

Change subject: Map should have `has` and `entries` methods
......................................................................

Map should have `has` and `entries` methods

Just like native Maps do.
Deprecate inappropriates uses of the Map to bring our implementation
closer to the standard [1]

We should be converging towards it so that in future this code can
be removed.

[1] 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

Bug:  T143463
Change-Id: I104e02f54cbd0dde7dd38e51fbd44819af440fab
---
M resources/src/mediawiki/mediawiki.js
1 file changed, 23 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/98/309698/1

diff --git a/resources/src/mediawiki/mediawiki.js 
b/resources/src/mediawiki/mediawiki.js
index db5a4fb..294c326 100644
--- a/resources/src/mediawiki/mediawiki.js
+++ b/resources/src/mediawiki/mediawiki.js
@@ -137,6 +137,14 @@
 
        Map.prototype = {
                /**
+                * Obtain all registered keys
+                *
+                * @return {Object}
+                */
+               entries: function () {
+                       return this.values;
+               },
+               /**
                 * Get the value of one or more keys.
                 *
                 * If called with no arguments, all values are returned.
@@ -171,7 +179,8 @@
                        }
 
                        if ( selection === undefined ) {
-                               return this.values;
+                               mw.log.warn( 'Use of `get` in this way is 
deprecated. Please use `entries`.' );
+                               return this.entries();
                        }
 
                        // Invalid selection key
@@ -202,6 +211,16 @@
                },
 
                /**
+                * Check if a key exists
+                *
+                * @param {string} key to check
+                * @return {boolean} True if the key(s) exist
+                */
+               has: function ( key ) {
+                       return typeof key === 'string' && hasOwn.call( 
this.values, key );
+               },
+
+               /**
                 * Check if one or more keys exist.
                 *
                 * @param {Mixed} selection Key or array of keys to check
@@ -211,14 +230,15 @@
                        var s;
 
                        if ( $.isArray( selection ) ) {
+                               mw.log.warn( 'Use of `exists` in this way is 
deprecated. Please use `has`.' );
                                for ( s = 0; s < selection.length; s++ ) {
-                                       if ( typeof selection[ s ] !== 'string' 
|| !hasOwn.call( this.values, selection[ s ] ) ) {
+                                       if ( typeof selection[ s ] !== 'string' 
|| !this.has( selection[ s ] ) ) {
                                                return false;
                                        }
                                }
                                return true;
                        }
-                       return typeof selection === 'string' && hasOwn.call( 
this.values, selection );
+                       return this.has( selection );
                }
        };
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I104e02f54cbd0dde7dd38e51fbd44819af440fab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

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

Reply via email to