array-changes-async
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -49,3 +49,3 @@ /*global setTimeout */ | ||
for (i = 0; i < mutatedArray.length && offsetIndex < index; i += 1) { | ||
if (mutatedArray[i].type !== 'remove') { | ||
if (mutatedArray[i].type !== 'remove' && mutatedArray[i].type !== 'moveSource') { | ||
offsetIndex++; | ||
@@ -79,6 +79,6 @@ } | ||
var added = removed.map(function (v) { | ||
return extend({}, v, { last: false, type: 'insert' }); | ||
return extend({}, v, { last: false, type: 'moveTarget' }); | ||
}); | ||
removed.forEach(function (v) { | ||
v.type = 'remove'; | ||
v.type = 'moveSource'; | ||
}); | ||
@@ -107,3 +107,3 @@ var insertIndex = offsetIndex(diffItem.to); | ||
var type = diffItem.type; | ||
if (type === 'remove') { | ||
if (type === 'remove' || type === 'moveSource') { | ||
offset -= 1; | ||
@@ -117,3 +117,3 @@ } else if (type === 'similar') { | ||
var conflicts = mutatedArray.reduce(function (conflicts, item) { | ||
return item.type === 'similar' ? conflicts : conflicts + 1; | ||
return item.type === 'similar' || item.type === 'moveSource' || item.type === 'moveTarget' ? conflicts : conflicts + 1; | ||
}, 0); | ||
@@ -120,0 +120,0 @@ |
{ | ||
"name": "array-changes-async", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "Array diffing", | ||
@@ -5,0 +5,0 @@ "main": "./lib/arrayChanges.js", |
@@ -130,11 +130,11 @@ /*global describe, it, setTimeout, Symbol*/ | ||
it('should treat moved items as removed and inserted', function () { | ||
it('should indicate moved items with two items', function () { | ||
return expect(promiseArrayChanges([1, 2, 3, 0], [0, 1, 2, 3], function (a, b, aIndex, bIndex, callback) { | ||
return callback(a === b); | ||
}), 'when fulfilled', 'to satisfy', [ | ||
{ type: 'insert', value: 0, last: false }, | ||
{ type: 'equal', value: 1, expected: 1 }, | ||
{ type: 'equal', value: 2, expected: 2 }, | ||
{ type: 'equal', value: 3, expected: 3 }, | ||
{ type: 'remove', value: 0, last: true } | ||
{ type: 'moveTarget', value: 0, last: false, actualIndex: 3 }, | ||
{ type: 'equal', value: 1, expected: 1, actualIndex: 0, expectedIndex: 1 }, | ||
{ type: 'equal', value: 2, expected: 2, actualIndex: 1, expectedIndex: 2 }, | ||
{ type: 'equal', value: 3, expected: 3, actualIndex: 2, expectedIndex: 3 }, | ||
{ type: 'moveSource', value: 0, actualIndex: 3, last: true } | ||
]); | ||
@@ -294,10 +294,13 @@ }); | ||
return expect(promiseArrayChanges( | ||
[ 4, 2, 3, 1 ], [ 100, 200, 300, 400 ], function (a, b, aIndex, bIndex, callback){ | ||
[ 4, 2, 3, 1 ], [ 100, 200, 300, 400 ], function (a, b, aIndex, bIndex, callback){ | ||
return callback(a * 100 === b); | ||
}, function (a, b, aIndex, bIndex, callback) { return callback(a * 100 === b); }), | ||
'when fulfilled', 'to satisfy', [ | ||
{ type: 'similar', value: 4, expected: 100 }, | ||
{ type: 'equal', value: 2, expected: 200 }, | ||
{ type: 'equal', value: 3, expected: 300 }, | ||
{ type: 'similar', value: 1, expected: 400 } | ||
{ type: 'moveTarget', actualIndex: 3, value: 1, last: false }, | ||
{ type: 'moveTarget', actualIndex: 1, value: 2, last: false }, | ||
{ type: 'moveTarget', actualIndex: 2, value: 3, last: false }, | ||
{ type: 'equal', actualIndex: 0, value: 4, expected: 400, expectedIndex: 3 }, | ||
{ type: 'moveSource', actualIndex: 1, value: 2 }, | ||
{ type: 'moveSource', actualIndex: 2, value: 3 }, | ||
{ type: 'moveSource', actualIndex: 3, value: 1, last: true } | ||
]); | ||
@@ -304,0 +307,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
37968
629
0