Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#128: Added fix to have reference equality check for datarows. #129

Closed
wants to merge 7 commits into from
14 changes: 13 additions & 1 deletion src/directives/hotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,26 @@
} else {
scope.hotInstance.loadData(newValue);
scope.htSettings.data = newValue;

}
} else if (newValue !== oldValue) {
scope.htSettings[key] = newValue;
settingFactory.updateHandsontableSettings(scope.hotInstance, scope.htSettings);
}
}, ['datarows', 'columns', 'rowHeights', 'colWidths', 'rowHeaders', 'colHeaders'].indexOf(key) >= 0);
});

/**
* Check for reference equality changes for datarows
* TODO: must the remaining bindingsKeys need to be added also if their reference changes
*/
scope.$watch('datarows', function(newValue) {
if (newValue === void 0) {
return;
}
if (scope.hotInstance.getSettings().data !== newValue) {
scope.hotInstance.loadData(newValue);
}
});

/**
* Check if data length has been changed
Expand Down
24 changes: 22 additions & 2 deletions test/directives/hotTable/watchingOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,29 @@ describe('hotTable - Watching options', function() {

scope.$digest();

expect(scope.hotInstance.getData()).toBe(rootScope.value);
expect(scope.hotInstance.getSettings().data).toBe(rootScope.value);
});

it('should ensure a new copy of `datarows` is made when the reference is changed but it has the same value', function() {
rootScope.value = [[1,2,3,4]];
var scope = angular.element(compile('<hot-table datarows="value"></hot-table>')(rootScope)).isolateScope();

scope.$digest();

expect(scope.hotInstance.getSettings().data).toBe(rootScope.value);

rootScope.value = [[1, 2, 3, 4]];

rootScope.$digest();

expect(scope.hotInstance.getSettings().data).toBe(rootScope.value);

rootScope.value.push([[5, 6, 7, 8]]);
scope.$digest();

expect(scope.hotInstance.getSettings().data).toBe(rootScope.value);
});

it('should create table with `dataSchema` attribute', function() {
rootScope.value = {id: null};
var scope = angular.element(compile('<hot-table dataschema="value"></hot-table>')(rootScope)).isolateScope();
Expand Down Expand Up @@ -831,4 +851,4 @@ describe('hotTable - Watching options', function() {
expect(scope.hotInstance.getSettings().className).toBe('foo');
expect(scope.hotInstance.getSettings().data).toEqual([[1]]);
});
});
});