angular/angular.js — pull request #7205 by joelhooks (2014-04-22 21:38:37+00:00)
Title: ngModelOptions debounce was failing when on event with a value of 0

Was testing ngModelOptions, and noticed that the provided example
`ngModelOptions="{ updateOn: 'default blur', debounce: {'default': 500, 'blur':
0} }"` didn't function. With a little investigating I determined that the logic
operation was skipping debounce[trigger] if it was 0 (thanks JS falsiness!).

My first solution was to do this:

```javascript
var debounceDelay = ctrl.$options && (
isObject(ctrl.$options.debounce)
? (isNumber(ctrl.$options.debounce[trigger]) ?
ctrl.$options.debounce[trigger]
:
(ctrl.$options.debounce['default']
|| 0))
: ctrl.$options.debounce
) || 0;
```

Which hopefully makes us all cringe. Instead of adding this mess (the original
logic took me about 30 minutes to understand), I decided to unroll it into
something a bit less... terse.

I added a unit test to cover this scenario.

This was found in **1.3.0-beta.6.**

[Here's a fiddle that demonstrates.](http://jsfiddle.net/joelhooks/QZ8hg/) Notice that it debounces blur, despite it being configured with 0. THis is because `(ctrl.$options.debounce[trigger] || ctrl.$options.debounce['default'] || 0)` will **always** skip to default if it exists and `debounce[trigger]` is 0. Without a default alongside the trigger, the final 0 would be the result, and I suspect that is how this slipped by.