Update vendor/underscore.

This commit is contained in:
John-David Dalton
2016-03-28 09:35:41 -07:00
parent 5d92b37550
commit 2ddd893ca2
3 changed files with 124 additions and 17 deletions

View File

@@ -475,9 +475,9 @@
});
QUnit.test('debounce asap', function(assert) {
assert.expect(4);
assert.expect(6);
var done = assert.async();
var a, b;
var a, b, c;
var counter = 0;
var incr = function(){ return ++counter; };
var debouncedIncr = _.debounce(incr, 64, true);
@@ -489,7 +489,13 @@
_.delay(debouncedIncr, 16);
_.delay(debouncedIncr, 32);
_.delay(debouncedIncr, 48);
_.delay(function(){ assert.equal(counter, 1, 'incr was debounced'); done(); }, 128);
_.delay(function(){
assert.equal(counter, 1, 'incr was debounced');
c = debouncedIncr();
assert.equal(c, 2);
assert.equal(counter, 2, 'incr was called again');
done();
}, 128);
});
QUnit.test('debounce asap cancel', function(assert) {

View File

@@ -565,6 +565,14 @@
assert.equal(_.isEqual({a: 0}, {a: -0}), false);
assert.equal(_.isEqual([NaN], [NaN]), true);
assert.equal(_.isEqual({a: NaN}, {a: NaN}), true);
if (typeof Symbol !== 'undefined') {
var symbol = Symbol('x');
assert.strictEqual(_.isEqual(symbol, symbol), true, 'A symbol is equal to itself');
assert.strictEqual(_.isEqual(symbol, Object(symbol)), true, 'Even when wrapped in Object()');
assert.strictEqual(_.isEqual(symbol, null), false, 'Different types are not equal');
}
});
QUnit.test('isEmpty', function(assert) {
@@ -673,6 +681,100 @@
assert.ok(_.isBoolean(false), 'and so is false');
});
QUnit.test('isMap', function(assert) {
assert.ok(!_.isMap('string'), 'a string is not a map');
assert.ok(!_.isMap(2), 'a number is not a map');
assert.ok(!_.isMap({}), 'an object is not a map');
assert.ok(!_.isMap(false), 'a boolean is not a map');
assert.ok(!_.isMap(void 0), 'undefined is not a map');
assert.ok(!_.isMap([1, 2, 3]), 'an array is not a map');
if (typeof Set === 'function') {
assert.ok(!_.isMap(new Set()), 'a set is not a map');
}
if (typeof WeakSet === 'function') {
assert.ok(!_.isMap(new WeakSet()), 'a weakset is not a map');
}
if (typeof WeakMap === 'function') {
assert.ok(!_.isMap(new WeakMap()), 'a weakmap is not a map');
}
if (typeof Map === 'function') {
var keyString = 'a string';
var obj = new Map();
obj.set(keyString, 'value');
assert.ok(_.isMap(obj), 'but a map is');
}
});
QUnit.test('isWeakMap', function(assert) {
assert.ok(!_.isWeakMap('string'), 'a string is not a weakmap');
assert.ok(!_.isWeakMap(2), 'a number is not a weakmap');
assert.ok(!_.isWeakMap({}), 'an object is not a weakmap');
assert.ok(!_.isWeakMap(false), 'a boolean is not a weakmap');
assert.ok(!_.isWeakMap(void 0), 'undefined is not a weakmap');
assert.ok(!_.isWeakMap([1, 2, 3]), 'an array is not a weakmap');
if (typeof Set === 'function') {
assert.ok(!_.isWeakMap(new Set()), 'a set is not a weakmap');
}
if (typeof WeakSet === 'function') {
assert.ok(!_.isWeakMap(new WeakSet()), 'a weakset is not a weakmap');
}
if (typeof Map === 'function') {
assert.ok(!_.isWeakMap(new Map()), 'a map is not a weakmap');
}
if (typeof WeakMap === 'function') {
var keyObj = {}, obj = new WeakMap();
obj.set(keyObj, 'value');
assert.ok(_.isWeakMap(obj), 'but a weakmap is');
}
});
QUnit.test('isSet', function(assert) {
assert.ok(!_.isSet('string'), 'a string is not a set');
assert.ok(!_.isSet(2), 'a number is not a set');
assert.ok(!_.isSet({}), 'an object is not a set');
assert.ok(!_.isSet(false), 'a boolean is not a set');
assert.ok(!_.isSet(void 0), 'undefined is not a set');
assert.ok(!_.isSet([1, 2, 3]), 'an array is not a set');
if (typeof Map === 'function') {
assert.ok(!_.isSet(new Map()), 'a map is not a set');
}
if (typeof WeakMap === 'function') {
assert.ok(!_.isSet(new WeakMap()), 'a weakmap is not a set');
}
if (typeof WeakSet === 'function') {
assert.ok(!_.isSet(new WeakSet()), 'a weakset is not a set');
}
if (typeof Set === 'function') {
var obj = new Set();
obj.add(1).add('string').add(false).add({});
assert.ok(_.isSet(obj), 'but a set is');
}
});
QUnit.test('isWeakSet', function(assert) {
assert.ok(!_.isWeakSet('string'), 'a string is not a weakset');
assert.ok(!_.isWeakSet(2), 'a number is not a weakset');
assert.ok(!_.isWeakSet({}), 'an object is not a weakset');
assert.ok(!_.isWeakSet(false), 'a boolean is not a weakset');
assert.ok(!_.isWeakSet(void 0), 'undefined is not a weakset');
assert.ok(!_.isWeakSet([1, 2, 3]), 'an array is not a weakset');
if (typeof Map === 'function') {
assert.ok(!_.isWeakSet(new Map()), 'a map is not a weakset');
}
if (typeof WeakMap === 'function') {
assert.ok(!_.isWeakSet(new WeakMap()), 'a weakmap is not a weakset');
}
if (typeof Set === 'function') {
assert.ok(!_.isWeakSet(new Set()), 'a set is not a weakset');
}
if (typeof WeakSet === 'function') {
var obj = new WeakSet();
obj.add({x: 1}, {y: 'string'}).add({y: 'string'}).add({z: [1, 2, 3]});
assert.ok(_.isWeakSet(obj), 'but a weakset is');
}
});
QUnit.test('isFunction', function(assert) {
assert.ok(!_.isFunction(void 0), 'undefined vars are not functions');
assert.ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');

View File

@@ -20,6 +20,7 @@
// Save bytes in the minified (but not gzipped) version:
var ArrayProto = Array.prototype, ObjProto = Object.prototype;
var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
// Create quick reference variables for speed access to core prototypes.
var push = ArrayProto.push,
@@ -218,12 +219,8 @@
// Return the first value which passes a truth test. Aliased as `detect`.
_.find = _.detect = function(obj, predicate, context) {
var key;
if (isArrayLike(obj)) {
key = _.findIndex(obj, predicate, context);
} else {
key = _.findKey(obj, predicate, context);
}
var keyFinder = isArrayLike(obj) ? _.findIndex : _.findKey;
var key = keyFinder(obj, predicate, context);
if (key !== void 0 && key !== -1) return obj[key];
};
@@ -442,7 +439,7 @@
// Keep surrogate pair characters together
return obj.match(reStrSymbol);
}
if (isArrayLike(obj)) return _.map(obj, _.identity);
if (isArrayLike(obj)) return _.map(obj);
return _.values(obj);
};
@@ -494,7 +491,7 @@
// Trim out all falsy values from an array.
_.compact = function(array) {
return _.filter(array, _.identity);
return _.filter(array);
};
// Internal implementation of a recursive `flatten` function.
@@ -859,12 +856,12 @@
};
var debounced = restArgs(function(args) {
var callNow = immediate && !timeout;
if (timeout) clearTimeout(timeout);
if (callNow) {
if (immediate) {
var callNow = !timeout;
timeout = setTimeout(later, wait);
result = func.apply(this, args);
} else if (!immediate) {
if (callNow) result = func.apply(this, args);
} else {
timeout = _.delay(later, wait, this, args);
}
@@ -1195,6 +1192,8 @@
// millisecond representations. Note that invalid dates with millisecond representations
// of `NaN` are not equivalent.
return +a === +b;
case '[object Symbol]':
return SymbolProto.valueOf.call(a) === SymbolProto.valueOf.call(b);
}
var areArrays = className === '[object Array]';
@@ -1285,8 +1284,8 @@
return type === 'function' || type === 'object' && !!obj;
};
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error', 'Symbol'], function(name) {
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError, isMap, isWeakMap, isSet, isWeakSet.
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error', 'Symbol', 'Map', 'WeakMap', 'Set', 'WeakSet'], function(name) {
_['is' + name] = function(obj) {
return toString.call(obj) === '[object ' + name + ']';
};