refactor(forms): Rename read() -> setViewValue()

This commit is contained in:
Vojta Jina 2012-03-09 16:58:48 -08:00
parent e0cc84ad7b
commit 83314913e7
3 changed files with 13 additions and 13 deletions

View file

@ -374,7 +374,7 @@ function textInputType(scope, element, attr, ctrl) {
if (ctrl.viewValue !== value) {
scope.$apply(function() {
ctrl.read(value);
ctrl.setViewValue(value);
});
} else if (touched) {
scope.$apply();
@ -559,7 +559,7 @@ function radioInputType(scope, element, attr, ctrl) {
if (element[0].checked) {
scope.$apply(function() {
ctrl.touch();
ctrl.read(attr.value);
ctrl.setViewValue(attr.value);
});
};
});
@ -580,7 +580,7 @@ function checkboxInputType(scope, element, attr, ctrl) {
element.bind('click', function() {
scope.$apply(function() {
ctrl.touch();
ctrl.read(element[0].checked);
ctrl.setViewValue(element[0].checked);
});
});
@ -830,7 +830,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
/**
* @ngdoc function
* @name angular.module.ng.$compileProvider.directive.ng-model.NgModelController#read
* @name angular.module.ng.$compileProvider.directive.ng-model.NgModelController#setViewValue
* @methodOf angular.module.ng.$compileProvider.directive.ng-model.NgModelController
*
* @description
@ -845,7 +845,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
*
* @param {string} value Value from the view
*/
this.read = function(value) {
this.setViewValue = function(value) {
this.viewValue = value;
forEach(this.parsers, function(fn) {
@ -1042,7 +1042,7 @@ var ngModelInstantDirective = ['$browser', function($browser) {
if (ctrl.viewValue !== value) {
scope.$apply(function() {
ctrl.read(value);
ctrl.setViewValue(value);
});
} else if (touched) {
scope.$apply();

View file

@ -168,7 +168,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selectElement.bind('change', function() {
scope.$apply(function() {
ctrl.touch();
ctrl.read(selectElement.val());
ctrl.setViewValue(selectElement.val());
});
});
}
@ -190,7 +190,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
}
});
ctrl.touch();
ctrl.read(array);
ctrl.setViewValue(array);
});
});
}
@ -270,7 +270,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
ctrl.touch();
if (ctrl.viewValue !== value) {
ctrl.read(value);
ctrl.setViewValue(value);
}
});
});

View file

@ -113,7 +113,7 @@ describe('NgModelController', function() {
describe('view -> model', function() {
it('should set the value to $viewValue', function() {
ctrl.read('some-val');
ctrl.setViewValue('some-val');
expect(ctrl.viewValue).toBe('some-val');
});
@ -131,7 +131,7 @@ describe('NgModelController', function() {
return value + '-b';
});
ctrl.read('init');
ctrl.setViewValue('init');
expect(log).toEqual(['init', 'init-a']);
expect(ctrl.modelValue).toBe('init-a-b');
});
@ -141,13 +141,13 @@ describe('NgModelController', function() {
var spy = jasmine.createSpy('$viewChange');
scope.$on('$viewChange', spy);
ctrl.read('val');
ctrl.setViewValue('val');
expect(spy).toHaveBeenCalledOnce();
spy.reset();
// invalid
ctrl.parsers.push(function() {return undefined;});
ctrl.read('val');
ctrl.setViewValue('val');
expect(spy).not.toHaveBeenCalled();
});
});