Skip to content

Instantly share code, notes, and snippets.

@lega911
Created December 18, 2015 18:52
Show Gist options
  • Save lega911/d4a3b81f37fbfb9018fb to your computer and use it in GitHub Desktop.
Save lega911/d4a3b81f37fbfb9018fb to your computer and use it in GitHub Desktop.
alight.filters.throttle = {
init: function(delay, scope) {
this.delay = Number(delay);
this.to = null;
this.scope = scope;
},
onChange: function(value) {
var that;
that = this;
if (this.to) {
clearTimeout(this.to);
}
this.to = setTimeout(function() {
that.to = null;
that.setValue(value);
that.scope.$scan();
}, this.delay);
}
};
alight.filters.throttle = {
init: function(delay, scope, env) {
delay = Number(delay);
var to = null;
return {
onChange: function(value) {
if(to) {
clearTimeout(to);
}
to = setTimeout(function() {
to = null;
env.setValue(value);
scope.$scan();
}, delay);
}
} // return
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment