Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/91336
Change subject: Update oojs to v1.0.5 ...................................................................... Update oojs to v1.0.5 Code: http://trevorparscal.github.io/oojs/releases/oojs-1.0.5.js Release notes: https://github.com/trevorparscal/oojs/blob/v1.0.5/History.md Change-Id: I1117bd5bef70783039db18849f85215fcb346ada --- M modules/oojs/oojs.js 1 file changed, 92 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/36/91336/1 diff --git a/modules/oojs/oojs.js b/modules/oojs/oojs.js index 829a843..d2d61e9 100644 --- a/modules/oojs/oojs.js +++ b/modules/oojs/oojs.js @@ -1,12 +1,12 @@ /*! - * Object Oriented JavaScript Library v1.0.4 + * Object Oriented JavaScript Library v1.0.5 * https://github.com/trevorparscal/oojs * * Copyright 2011-2013 OOJS Team and other contributors. * Released under the MIT license * http://oojs.mit-license.org * - * Date: Fri Oct 11 2013 02:49:44 GMT+0200 (CEST) + * Date: Wed Oct 23 2013 02:22:02 GMT+0200 (CEST) */ ( function ( global ) { @@ -107,9 +107,6 @@ // Extend static properties - always initialize both sides originFn.static = originFn.static || {}; targetFn.static = Object.create( originFn.static ); - - // Copy mixin tracking - targetFn.mixins = originFn.mixins ? originFn.mixins.slice( 0 ) : []; }; /** @@ -360,6 +357,96 @@ return val; } }; + +/** + * Compute the union (duplicate-free merge) of a set of arrays. + * + * 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 + * + * @param {Array...} arrays Arrays to union + * @returns {Array} Union of the arrays + */ +oo.simpleArrayUnion = function () { + var i, ilen, arr, j, jlen, + obj = {}, + result = []; + + for ( i = 0, ilen = arguments.length; i < ilen; i++ ) { + arr = arguments[i]; + for ( j = 0, jlen = arr.length; j < jlen; j++ ) { + if ( !obj[ arr[j] ] ) { + obj[ arr[j] ] = true; + result.push( arr[j] ); + } + } + } + + return result; +}; + +/** + * Combine arrays (intersection or difference). + * + * An intersection checks the item exists in 'b' while difference checks it doesn't. + * + * 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 + * @param {Array} a First array + * @param {Array} b Second array + * @param {boolean} includeB Whether to items in 'b' + * @returns {Array} Combination (intersection or difference) of arrays + */ +function simpleArrayCombine( a, b, includeB ) { + var i, ilen, isInB, + bObj = {}, + result = []; + + for ( i = 0, ilen = b.length; i < ilen; i++ ) { + bObj[ b[i] ] = true; + } + + for ( i = 0, ilen = a.length; i < ilen; i++ ) { + isInB = !!bObj[ a[i] ]; + if ( isInB === includeB ) { + result.push( a[i] ); + } + } + + return result; +} + +/** + * Compute the intersection of two arrays (items in both arrays). + * + * Arrays values must be convertable to object keys (strings) + * + * @param {Array} a First array + * @param {Array} b Second array + * @returns {Array} Intersection of arrays + */ +oo.simpleArrayIntersection = function ( a, b ) { + return simpleArrayCombine( a, b, true ); +}; + +/** + * Compute the difference of two arrays (items in 'a' but not 'b'). + * + * Arrays values must be convertable to object keys (strings) + * + * @param {Array} a First array + * @param {Array} b Second array + * @returns {Array} Intersection of arrays + */ +oo.simpleArrayDifference = function ( a, b ) { + return simpleArrayCombine( a, b, false ); +}; /** * Event emitter. * -- To view, visit https://gerrit.wikimedia.org/r/91336 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1117bd5bef70783039db18849f85215fcb346ada Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Krinkle <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
