Comparing version 7.0.0 to 7.0.1
/*! | ||
* OOjs v6.0.0-dev | ||
* OOjs v7.0.1 | ||
* https://www.mediawiki.org/wiki/OOjs | ||
@@ -553,8 +553,3 @@ * | ||
OO.unique = function ( arr ) { | ||
return arr.reduce( function ( result, current ) { | ||
if ( result.indexOf( current ) === -1 ) { | ||
result.push( current ); | ||
} | ||
return result; | ||
}, [] ); | ||
return Array.from( new Set( arr ) ); | ||
}; | ||
@@ -565,27 +560,19 @@ | ||
* | ||
* Arrays values must be convertable to object keys (strings). | ||
* | ||
* By building an object (with the values for keys) in parallel with | ||
* the array, a new item's existence in the union can be computed faster. | ||
* | ||
* @memberof OO | ||
* @method simpleArrayUnion | ||
* @param {...Array} arrays Arrays to union | ||
* @param {Array} a First array | ||
* @param {...Array} rest Arrays to union | ||
* @return {Array} Union of the arrays | ||
*/ | ||
OO.simpleArrayUnion = function () { | ||
var obj = {}; | ||
var result = []; | ||
OO.simpleArrayUnion = function ( a, ...rest ) { | ||
var set = new Set( a ); | ||
for ( var i = 0, ilen = arguments.length; i < ilen; i++ ) { | ||
var arr = arguments[ i ]; | ||
for ( var j = 0, jlen = arr.length; j < jlen; j++ ) { | ||
if ( !obj[ arr[ j ] ] ) { | ||
obj[ arr[ j ] ] = true; | ||
result.push( arr[ j ] ); | ||
} | ||
for ( var i = 0; i < rest.length; i++ ) { | ||
var arr = rest[ i ]; | ||
for ( var j = 0; j < arr.length; j++ ) { | ||
set.add( arr[ j ] ); | ||
} | ||
} | ||
return result; | ||
return Array.from( set ); | ||
}; | ||
@@ -598,7 +585,2 @@ | ||
* | ||
* Arrays values must be convertable to object keys (strings). | ||
* | ||
* By building an object (with the values for keys) of 'b' we can | ||
* compute the result faster. | ||
* | ||
* @private | ||
@@ -611,11 +593,7 @@ * @param {Array} a First array | ||
function simpleArrayCombine( a, b, includeB ) { | ||
var bObj = {}; | ||
var set = new Set( b ); | ||
var result = []; | ||
for ( var i = 0; i < b.length; i++ ) { | ||
bObj[ b[ i ] ] = true; | ||
} | ||
for ( var j = 0; j < a.length; j++ ) { | ||
var isInB = !!bObj[ a[ j ] ]; | ||
var isInB = set.has( a[ j ] ); | ||
if ( isInB === includeB ) { | ||
@@ -632,4 +610,2 @@ result.push( a[ j ] ); | ||
* | ||
* Arrays values must be convertable to object keys (strings). | ||
* | ||
* @memberof OO | ||
@@ -648,4 +624,2 @@ * @method simpleArrayIntersection | ||
* | ||
* Arrays values must be convertable to object keys (strings). | ||
* | ||
* @memberof OO | ||
@@ -1698,25 +1672,2 @@ * @method simpleArrayDifference | ||
// The constructor of native ES6 classes enforces use of the `new` operator through | ||
// a check that we cannot approximate or bypass from generic ES5-compatible code, | ||
// and thus would throw an error if we used Object.create() + Function.apply(). | ||
// | ||
// Instead, in order to construct an ES6 class with variable arguments, one has to use | ||
// either native E6-only syntax (new + spread operator) which prevents the entire library | ||
// from being available to older browsers, or one has to use the ES6 Reflect API. | ||
// We choose the latter. | ||
// | ||
var construct = ( typeof Reflect !== 'undefined' && Reflect.construct ) ? Reflect.construct : | ||
// This is used and covered via Karma in IE11, but we don't collect coverage there. | ||
/* istanbul ignore next */ | ||
function ( target, args ) { | ||
// We can't use the "new" operator with .apply directly because apply needs a | ||
// context. So instead just do what "new" does: create an object that inherits from | ||
// the constructor's prototype (which also makes it an "instanceof" the constructor), | ||
// then invoke the constructor with the object as context, and return it (ignoring | ||
// any constructor's return value). | ||
var obj = Object.create( target.prototype ); | ||
target.apply( obj, args ); | ||
return obj; | ||
}; | ||
/** | ||
@@ -1733,3 +1684,3 @@ * Create an object based on a key. | ||
*/ | ||
OO.Factory.prototype.create = function ( key ) { | ||
OO.Factory.prototype.create = function ( key, ...args ) { | ||
var constructor = this.lookup( key ); | ||
@@ -1740,9 +1691,3 @@ if ( !constructor ) { | ||
// Convert arguments to array and shift the first argument (key) off | ||
var args = []; | ||
for ( var i = 1; i < arguments.length; i++ ) { | ||
args.push( arguments[ i ] ); | ||
} | ||
return construct( constructor, args ); | ||
return new constructor( ...args ); | ||
}; | ||
@@ -1760,3 +1705,1 @@ | ||
}( this ) ); | ||
//# sourceMappingURL=oojs.js.map |
{ | ||
"name": "oojs", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "Power for object oriented JavaScript libraries.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
7
80376
1569