jenkins-bot has submitted this change and it was merged.
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, 7 insertions(+), 5 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
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..3ce52e3 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js
@@ -43,7 +43,7 @@
assert.strictEqual( window.mw, window.mediaWiki, 'mw alias to
mediaWiki' );
} );
- QUnit.test( 'mw.Map', 27, function ( assert ) {
+ QUnit.test( 'mw.Map', 28, function ( assert ) {
var arry, conf, funky, globalConf, nummy, someValues;
conf = new mw.Map();
@@ -102,6 +102,8 @@
'lorem': 'ipsum'
}, 'Map.get returns multiple values correctly as an object' );
+ assert.deepEqual( conf, new mw.Map( conf.values ), '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: merged
Gerrit-Change-Id: Id9f8d9569de8889fc3ffa24a6e7f4afca1aeabee
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits