Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngModelOptions): support for easily debouncing default only #15411

Closed
gkalpak opened this issue Nov 18, 2016 · 3 comments · Fixed by angular-indonesia/angular.js#88 or javascript-indonesias/angular.js#32

Comments

@gkalpak
Copy link
Member

gkalpak commented Nov 18, 2016

Do you want to request a feature or report a bug?
Feature.

What is the current behavior?
The delay specified in an ngModelOptions' debounce.default property will be used as a "catch-all" value, debouncing all updateOn events that don't explicitly specifiy a debounce delay.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).
Demo

What is the expected behavior?
debounce.default should only apply to the default event.
For a "catch-all" delay, we could use the '*' property, which is similar to how it is used for defining inheritance in ngModelOptions. E.g.

{
  updateOn: 'default blur keyup keydown',
  debounce: {default: 100, blur: 0, '*': 333}
}

What is the motivation / use case for changing the behavior?
The current behavior can be confusing, since updateOn supports a special event, default which means the default input event for that input/browser. With the proposed change, it will be still possible to provide a "catch-all" delay (via '*') and debounce.default will only affect the default event, which is more intuitive. Additionally, it will be easier to apply debouncing on the default event only, without having to explicitly set delays for all other supported events.

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
Probably 1.3+.

@petebacondarwin
Copy link
Member

I believe we can do this without a BC if we fallback on default if there is no "*"

@petebacondarwin petebacondarwin self-assigned this Nov 18, 2016
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Nov 18, 2016
This change enables the use of a `"*"` key in the `debounce` setting of
`ngModelOptions`, which will set the debounce value for all events that
do not have an explicit value.

Closes angular#15411
@gkalpak
Copy link
Member Author

gkalpak commented Nov 18, 2016

I believe we can do this without a BC if we fallback on default if there is no "*"

This would fix most of the issue (i.e you would still need and extra '*': 0 if you only want to debounce default), but would make the API even less intuitive imo. I would prefer to leave it as is (and maybe document it better), than introducing more compexity into the rules.

@petebacondarwin petebacondarwin modified the milestones: 1.6.0-rc.1, 1.7.0 Nov 18, 2016
@petebacondarwin
Copy link
Member

OK, in which case we will need a BC and it should be done in 1.7

@petebacondarwin petebacondarwin removed their assignment Oct 31, 2017
@Narretz Narretz self-assigned this Nov 15, 2017
Narretz added a commit to Narretz/angular.js that referenced this issue Nov 21, 2017
…ce catch-all

Closes angular#15411

BREAKING CHANGE:

the 'default' key in 'debounce' now only debounces the default event, i.e. the event
that is added as an update trigger by the different input directives automatically.

Previously, it also applied to other update triggers defined in 'updateOn' that
did not have a corresponding key in the 'debounce'.

This behavior is now supported via a special wildcard / catch-all key: '*'.

See the following example:

Pre-1.7:
'mouseup' is debounced by 500 milliseconds because 'default' is applied.
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500, 'blur': 0 }
}
```

1.7:
'mouseup' is debounced by 1000 milliseconds because '*' is applied.
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500, 'blur': 0, '*': 1000 }
}
```
Narretz added a commit to Narretz/angular.js that referenced this issue Nov 21, 2017
…ult' only

Closes angular#15411

BREAKING CHANGE:

the 'default' key in 'debounce' now only debounces the default event, i.e. the event
that is added as an update trigger by the different input directives automatically.

Previously, it also applied to other update triggers defined in 'updateOn' that
did not have a corresponding key in the 'debounce'.

This behavior is now supported via a special wildcard / catch-all key: '*'.

See the following example:

Pre-1.7:
'mouseup' is debounced by 500 milliseconds because 'default' is applied.
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500, 'blur': 0 }
}
```

1.7:
'mouseup' is debounced by 1000 milliseconds because '*' is applied.
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500, 'blur': 0, '*': 1000 }
}
```
Narretz added a commit to Narretz/angular.js that referenced this issue Nov 21, 2017
…ult' only

Closes angular#15411

BREAKING CHANGE:

the 'default' key in 'debounce' now only debounces the default event, i.e. the event
that is added as an update trigger by the different input directives automatically.

Previously, it also applied to other update triggers defined in 'updateOn' that
did not have a corresponding key in the 'debounce'.

This behavior is now supported via a special wildcard / catch-all key: '*'.

See the following example:

Pre-1.7:
'mouseup' is also debounced by 500 milliseconds because 'default' is applied:
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500, 'blur': 0 }
}
```

1.7:
The pre-1.7 behavior can be re-created by setting '*' as a catch-all debounce value:
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { '*': 500, 'blur': 0 }
}
```

In contrast, when 'default' is used, 'blur' and 'mouseup' are not debounced:
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500 }
}
```
Narretz added a commit to Narretz/angular.js that referenced this issue Nov 21, 2017
…ult' only

Closes angular#15411

BREAKING CHANGE:

the 'default' key in 'debounce' now only debounces the default event, i.e. the event
that is added as an update trigger by the different input directives automatically.

Previously, it also applied to other update triggers defined in 'updateOn' that
did not have a corresponding key in the 'debounce'.

This behavior is now supported via a special wildcard / catch-all key: '*'.

See the following example:

Pre-1.7:
'mouseup' is also debounced by 500 milliseconds because 'default' is applied:
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500, 'blur': 0 }
}
```

1.7:
The pre-1.7 behavior can be re-created by setting '*' as a catch-all debounce value:
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { '*': 500, 'blur': 0 }
}
```

In contrast, when only 'default' is used, 'blur' and 'mouseup' are not debounced:
```
ng-model-options="{
  updateOn: 'default blur mouseup',
  debounce: { 'default': 500 }
}
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.