Ori.livneh has uploaded a new change for review.

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


Change subject: mw.Map: add ability to map over an existing object other than 
'window'
......................................................................

mw.Map: add ability to map over an existing object other than 'window'

I don't love the fact that mw.Map features so prominently in mediawiki.js, but
since it's there to stay it might as well be useful for a wider range of use
cases. This patch makes it possible to pass an existing value-bearing object to
be mapped over to the Map constructor.

The effect is the same as constructing the object and then overriding its
'values' attribute. But doing that feels like you're sneaking around the back
to hack the API. Making it part of the official API makes it OK to do.

Change-Id: Id9f8d9569de8889fc3ffa24a6e7f4afca1aeabee
---
M resources/mediawiki/mediawiki.js
M tests/qunit/suites/resources/mediawiki/mediawiki.test.js
2 files changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/50/92450/1

diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js
index 03248ba..28fdcc4 100644
--- a/resources/mediawiki/mediawiki.js
+++ b/resources/mediawiki/mediawiki.js
@@ -74,11 +74,11 @@
         * @class mw.Map
         *
         * @constructor
-        * @param {boolean} [global=false] Whether to store the values in the 
global window
-        *  object or a exclusively in the object property 'values'.
+        * @param {Object|boolean} [values] Value-bearing object to map, or 
boolean
+        *  true to map over the global object. Defaults to an empty object.
         */
-       function Map( global ) {
-               this.values = global === true ? window : {};
+       function Map( values ) {
+               this.values = values === true ? window : ( values || {} );
                return this;
        }
 
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js 
b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
index 502b55b..8ba7850 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
@@ -102,6 +102,8 @@
                        'lorem': 'ipsum'
                }, 'Map.get returns multiple values correctly as an object' );
 
+               assert.deepEqual( conf, new mw.Map( someValues ), 'new mw.Map 
maps over existing values-bearing object' );
+
                assert.deepEqual( conf.get( ['foo', 'notExist'] ), {
                        'foo': 'bar',
                        'notExist': null

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9f8d9569de8889fc3ffa24a6e7f4afca1aeabee
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