feat(ngPluralize): add support for bind-once in `count`

The 1st commit contains the change and test for adding support for `bindOnce` in `count`.
The 2nd commit contains some nimor refactoring (mainly to avoid repetitive actions).

Closes #10004
(Makes #5452 obsolete)
Sorry, I mean the function that converts the number into what at
ngPluralizeCountWatch
is called `count`

On Fri, Nov 14, 2014 at 6:16 PM, Lucas Mirelmann <lgalfaso@gmail.com> wrote:

> You have to do `scope.$watch($parse(expression, fn), ...);`
> where fn is `ngPluralizeCountWatch`
>
> On Fri, Nov 14, 2014 at 11:45 AM, Georgios Kalpakas <
> notifications@github.com> wrote:
>
>> In src/ng/directive/ngPluralize.js:
>>
>> >
>> > -      scope.$watch(function ngPluralizeWatch() {
>> > -        var value = parseFloat(scope.$eval(numberExp));
>> > +      scope.$watch(numberExp, function ngPluralizeCountWatchAction(newVal) {
>> > +        var count = parseFloat(newVal);
>>
>> @lgalfaso <https://github.com/lgalfaso>: Hm...I could really use a hint
>> here. How could be use an interceptor and how would an interceptor make
>> lastCount unnecessary ?
>>
>> The only thing that I could think of and would make lastCount
>> unnecessary is moving part of the logic in the "watch" function instead of
>> in the "action" function:
>>
>>   var numberExpGetter = $parse(numberExp);
>>   scope.$watch(function ngPluralizeCountWatch() {
>>     var count = parseFloat(numberExpGetter(scope));
>>     if (!isNaN(count) && !(count in whens)) {
>>       count = $locale.pluralCat(count - offset);
>>     }
>>     return count;
>>   }, function ngPluralizeCountWatchAction(newVal) {
>>       watchRemover();
>>       watchRemover = scope.$watch(whensExpFns[newVal], updateElementText);
>>   });
>>
>> But considering how "watch" functions should be as lightweight as
>> possible, it seems clearly wrong to me to put an extra parseFloat +
>> isNaN + (... in ...) + $locale.pluralCat in every $digest loop.
>>
>> There is probably a way to let $parse know that ngPluralCountWatch
>> depends on numberExpGetter(scope) (so it doesn't have to execute the
>> rest of the logic if the "input" hasn't change), but like I said I could
>> use a hint on how to achieve this through $watch.
>>
>> —
>> Reply to this email directly or view it on GitHub
>> <https://github.com/angular/angular.js/pull/10022/files#r20352580>.
>>
>
>