-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(ngModelOptions): introduce $cancelUpdate to cancel pending updates #7014
Conversation
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@@ -1693,19 +1693,19 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ | |||
|
|||
/** | |||
* @ngdoc method | |||
* @name ngModel.NgModelController#$cancelDebounce | |||
* @name ngModel.NgModelController#$cancelUpdate | |||
* | |||
* @description | |||
* Cancel a pending debounced update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be something like "Cancel an update and reset the input element's value to prevent an update to the $viewValue
, which may be caused by a pending debounced event or because the input is waiting for a some future event."
@shahata - thanks for putting this together. It will be great to get this in before the next release so we have a solid feature. Given the potential for confusion when doing programmatic changes, we could do with a new section in the guide that explains how to deal with the various situations that you highlighted. |
Also we could do with some more information in the |
$cancelUpdate cancels any debounce action and resets the view value by invoking $render. this method should be invoked before programmatic update to the model of input that might have pending updates due to updateOn or debounced actions.
@petebacondarwin - thanks for the feedback. I went ahead and pushed an amended commit with the items you mentioned. You are right about the needed documentation enhancements, I will do it tomorrow night. |
Nice work! |
}, debounceDelay); | ||
} else { | ||
that.$$realSetViewValue(value); | ||
this.$$realSetViewValue(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be ctrl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It is in the context of this.$setViewValue
...
BTW, I was wondering - what do you think about using ctrl
everywhere? It will be a bit less clear, but it would minify better. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone calls $setViewValue
as a free function then this would fail, or am I wrong?
I think using ctrl everywhere is a good idea for general safety and consistency, although I suspect that a good minifier might swap out this
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uglify doesn't swap this
and I believe minifiers try not to do that since it is risky (by this
you could in theory actually be referring to the context in which the function was invoked and not the context in which it was defined, so swapping this automatically could result in breaking your code in a very hard to debug fashion :) )
@petebacondarwin I've added the docs & refactoring commits to this PR, would be great if you can review |
Will do today
|
that.$cancelDebounce(); | ||
if ( debounceDelay ) { | ||
$timeout.cancel(pendingDebounce); | ||
if (debounceDelay) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot on the parenthesis styling
👍 |
Thanks for all the help with this @shahata. |
$cancelUpdate cancels any debounce action and resets the view value by invoking $render. this method should be invoked before programmatic update to the model of input that might have pending updates due to updateOn or debounced actions. Fixes #6994