if ( !( langData[ langCode ] instanceof mw.Map ) ) {
langData[ langCode ] = new mw.Map();
}
- langData[ langCode ].set( dataKey, value );
+ if ( arguments.length > 2 ) {
+ langData[ langCode ].set( dataKey, value );
+ } else {
+ langData[ langCode ].set( dataKey );
+ }
}
};
// Override #set to also set the global variable
this.set = function ( selection, value ) {
var s;
-
- if ( $.isPlainObject( selection ) ) {
- for ( s in selection ) {
- setGlobalMapValue( this, s, selection[ s ] );
+ if ( arguments.length > 1 ) {
+ if ( typeof selection !== 'string' ) {
+ return false;
}
+ setGlobalMapValue( this, selection, value );
return true;
}
- if ( typeof selection === 'string' && arguments.length ) {
- setGlobalMapValue( this, selection, value );
+ if ( typeof selection === 'object' ) {
+ for ( s in selection ) {
+ setGlobalMapValue( this, s, selection[ s ] );
+ }
return true;
}
return false;
*/
set: function ( selection, value ) {
var s;
-
- if ( $.isPlainObject( selection ) ) {
- for ( s in selection ) {
- this.values[ s ] = selection[ s ];
+ // Use `arguments.length` because `undefined` is also a valid value.
+ if ( arguments.length > 1 ) {
+ if ( typeof selection !== 'string' ) {
+ return false;
}
+ this.values[ selection ] = value;
return true;
}
- if ( typeof selection === 'string' && arguments.length > 1 ) {
- this.values[ selection ] = value;
+ if ( typeof selection === 'object' ) {
+ for ( s in selection ) {
+ this.values[ s ] = selection[ s ];
+ }
return true;
}
return false;
assert.strictEqual( conf.set( funky, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' );
assert.strictEqual( conf.set( arry, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' );
assert.strictEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' );
+ assert.strictEqual( conf.set( null, 'Null' ), false, 'Map.set returns false if key is invalid (null)' );
+ assert.strictEqual( conf.set( {}, 'Object' ), false, 'Map.set returns false if key is invalid (plain object)' );
conf.set( String( nummy ), 'I used to be a number' );