Last active
November 26, 2020 07:18
-
-
Save myjpa/10313774 to your computer and use it in GitHub Desktop.
Debounced Ember TextField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monkey patching Ember.TextField so that you can add delay=500 to make the | |
# TextField to update the binding value in debounced manner with delay of 500ms. | |
# That is it will only update the value if there is a unsubmitted change and | |
# no user input for the specified delay period. | |
# While no delay spcified, it's just the plain Ember.TextField | |
# usage in handlebars: | |
# {{view Ember.TextField valueBinding="someValue" delay=500}} | |
Ember.TextField.reopen { | |
delay: null # delayed period for updating the binding value in ms | |
_debouncedSet: (key,value,delay)->Ember.run.debounce(this, Ember.set, this, key, value, delay) | |
_elementValueDidChange: () -> | |
if this.get('delay') | |
this._debouncedSet('value', this.$().val(), this.get('delay')) | |
else | |
Ember.set(this, 'value', this.$().val()) # this is the original implementation in ember | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment