I have an observer in a controller that saves the object as changes are made. The problem is it is happing too often.
changed: ( ->
#save code goes here
).observes("description")
I am thinking something like http://underscorejs.org/#debounce is needed?
Also It seems to save the object twice once when the attribute changes via a key input and then again when the attribute is set from the returned server value.
Any help would be great I am trying to wrap my head around ember.
RxJS debounce() Filtering Operator RxJS debounce() operator is a filtering operator that emits a value from the source Observable only after a while (exactly after a particular period). The emission is determined by another input given as Observable or promise.
The amount of time, in seconds, that elapses before the downlink interfaces are brought up after a state change of the uplink interfaces.
5 min. A debounce system is a set of code that keeps a function from running too many times. It comes from the idea of mechanical switch bounce, where a pushed switch bounces and creates multiple signals. In Roblox, this problem occurs mainly with the BasePart.
The debounce function delays the processing of the keyup event until the user has stopped typing for a predetermined amount of time. This prevents your UI code from needing to process every event and also drastically reduces the number of API calls sent to your server.
From Ember 1.0.0, you can get a debounced observer in any View or Object by wrapping the debounce call inside another function that observes. Ember.run.debounce
doesn't return a function but instead adds the function handle to a dictionary. Every subsequent time Ember.run.debounce gets called with that function handle it will check the dictionary to see the last time the function was called and debounce it as expected.
var MyView = Ember.View.extend({
calledRarely: function() {
console.log("This will log rarely.");
},
calledOften: function() {
console.log("This will log often.");
Ember.run.debounce(this, this.calledRarely, 1000);
}.observes("propertyThatChangesOften")
});
Here, this.calledOften
isn't debounced at all so Ember.run.debounce
will actually be called as often as the property is changed. It won't call this.calledRarely
until our debounce timeout has completed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With