Skip to content

Commit

Permalink
Fixed minor undo bug which would undo more if a string change and a n…
Browse files Browse the repository at this point in the history
…on string change occurred simultaneously. Updated tag to 1.0.9. Preveneted checking null objects in archive lookup
  • Loading branch information
SamMaier committed Jan 23, 2015
1 parent 3bdd511 commit cf61880
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chronicle",
"main": "chronicle.js",
"version": "1.0.2",
"version": "1.0.9",
"authors": [
"Sam Maier <sam@sammaier.ca>"
],
Expand Down
23 changes: 18 additions & 5 deletions chronicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@
if (isArray(o1)) {
if (!isArray(o2)) return {isEqual: false, unequalVariable: '', stringDiff: false, o1: o1, o2: o2};
if ((length = o1.length) == o2.length) {
var returnEq = {isEqual: true, unequalVariable: '', stringDiff: false, o1: o1, o2: o2};
for(key=0; key<length; key++) {
var eq = equals(o1[key], o2[key]);
if (!eq.isEqual){
eq.unequalVariable = '['+String(key)+']' + eq.unequalVariable;
return eq;
if (!eq.stringDiff){
return eq;
} else {
returnEq = eq;
}
}
}
return {isEqual: true, unequalVariable: '', stringDiff: false, o1: o1, o2: o2};
return returnEq;
}
} else if (isDate(o1)) {
return {isEqual: isDate(o2) && o1.getTime() == o2.getTime(), unequalVariable: '', stringDiff: false, o1: o1, o2: o2};
Expand All @@ -60,12 +65,17 @@
} else {
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || isArray(o2)) return {isEqual: false, unequalVariable: '', stringDiff: false, o1: o1, o2: o2};
keySet = {};
var returnEq = {isEqual: true, unequalVariable: '', stringDiff: false, o1: o1, o2: o2}
for(key in o1) {
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
var eq = equals(o1[key], o2[key]);
if (!eq.isEqual){
eq.unequalVariable = '.'+String(key) + eq.unequalVariable;
return eq;
if (!eq.stringDiff){
return eq;
} else {
returnEq = eq;
}
}
keySet[key] = true;
}
Expand All @@ -75,7 +85,7 @@
o2[key] !== undefined &&
!isFunction(o2[key])) return {isEqual: false, unequalVariable: '', stringDiff: false, o1: o1, o2: o2};
}
return {isEqual: true, unequalVariable: '', stringDiff: false, o1: o1, o2: o2};
return returnEq;
}
}
}
Expand Down Expand Up @@ -387,7 +397,10 @@
//We only consider them too similar if the same variable was changed last time and this time and their differences are considered to not be big enough by tooSimilar()
//Too similar means the
var tooSim = tooSimilar(differenceObject.differences);
if (tooSim){
if (typeof($parse('watchVar'+eq.unequalVariable)(this.archive[this.currArchivePos-1])) != 'string'){
tooSim = false;
}
else if (tooSim){
//Checks to see if the length of the string that was changed is more than MAX_STRING_CHANGE_SIZE characters in length different in the most recent entry than in the previous entry.
//($parse('watchVar'+eq.unequalVariable)(this.archive[this.currArchivePos-1]) is the most confusing part, it boils down as such:
//$parse('watchVar'+eq.unequalVariable) is the parsedUnequalVariable but swapping out 'watchVar' for this.watchVar (a string containing the name of the watch var in the scope)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Angular-Chronicle",
"version": "1.0.6",
"version": "1.0.9",
"description": "An undo/redo service for AngularJS.",
"main": "chronicle.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions test/stringHandlingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe( 'Chronicle string handling', function() {
expect(scope.chronicle.archive[1].watchVar.str).toEqual("abcdefghij1234567890");
}));

it( 'should not remove a change if non string stuff is happening', inject( function() {
scope.obj.str = "abcdef";
scope.$apply();
scope.obj.str = "abcdefg";
scope.obj.zzz = 1;
scope.$apply();

expect(scope.chronicle.archive[1].watchVar.str).toEqual("abcdef");
}));

it( 'should not add a new entry in the archive if there is a 14 character difference and its not the first one', inject( function() {
scope.obj.str = "abcdef";
scope.$apply();
Expand Down

0 comments on commit cf61880

Please sign in to comment.