Add fast path for objects with a single primitive value back to _.matches and add isStrictComparable helper to reduce _.matches and _.isEqual.

This commit is contained in:
John-David Dalton
2014-07-10 09:26:20 -07:00
parent 884c2af17d
commit 1631ceedb3
2 changed files with 44 additions and 35 deletions

View File

@@ -6721,24 +6721,24 @@
strictEqual(matches(otherObject), false);
});
test('should not change match behavior if `source` is augmented', 6, function() {
_.each([{ 'a': 1, 'b': 2 }, { 'a': { 'b': 2, 'c': 3 } }], function(source, index) {
test('should not change match behavior if `source` is augmented', 9, function() {
_.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
var object = _.cloneDeep(source),
matches = _.matches(source);
strictEqual(matches(object), true, 'a' + index);
strictEqual(matches(object), true);
if (index) {
source.a.b = 1;
source.a.c = 2;
source.a.d = 3;
} else {
source.a = 2;
source.b = 1;
source.c = 3;
} else {
source.a.b = 1;
source.a.c = 2;
source.a.d = 3;
}
strictEqual(matches(object), true, 'b' + index);
strictEqual(matches(source), false, 'c' + index);
strictEqual(matches(object), true);
strictEqual(matches(source), false);
});
});