angular/angular.js — pull request #8941 by tbosch (2014-09-05 00:51:15+00:00)
Title: WIP: refactor(ngModelController,formController):

I am assigned to following issues and found that the current
logic for async validation in ngModelController and formController
is not maintainable:
- control logic is in multiple parts, e.g. `ctrl.$setValidity`
waits for end of promises
- logic for updating the flags `ctrl.$error`, `ctrl.$pending`, `ctrl.$valid`
is super complicated, especially in formController

I made the following changes (almost through, only some tests are still
failing):
- simplify async validation: centralize control logic
into one method
* remove counters `invalidCount` and `pendingCount`
* use a flag `currentValidationRunId` to separate
async validator runs from each other
* use `$q.all` to determine when all async validators are done
* remove fields from `ctrl.$error` that are valid,
instead of leaving them there with value `false`
-> make logic more consistent
* remove diff calculation, always calculate the correct state anew,
only cache the css classes that have been set to not
trigger too many css animations.
- centralize way how `ctrl.$modelValue` and `ctrl.$invalidModelValue`
is updated
- simplify `ngModelController/formCtrl.$setValidity` and merge
`$$setPending`, `$$clearControlValidity/$$clearValidity/$$clearPending`
into one method, that has the same code in `ngModelController` AND
`formController`
- minor bug fixes encountered in the tests because of this centralization:
* only read out `input.validity.badInput`, but not `input.validity.typeMismatch`,
as parser error (leads to problems when using `type=email`)

@matsko What do you think?
/cc @IgorMinar