Skip to content

Instantly share code, notes, and snippets.

@foxnewsnetwork
Created May 10, 2018 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxnewsnetwork/4fc498090541439d814721145c6494a1 to your computer and use it in GitHub Desktop.
Save foxnewsnetwork/4fc498090541439d814721145c6494a1 to your computer and use it in GitHub Desktop.
debounce-action
import Ember from 'ember';
export default Ember.Component.extend({
tagName: '',
after: 0,
willDestroyElement() {
Ember.run.cancel(this.timeoutHandle);
},
actions: {
out(...args) {
Ember.run.cancel(this.timeoutHandle);
const { action, after } = this.getProperties('action', 'after');
this.timeoutHandle = Ember.run.later(() => action(...args), after);
}
}
}).reopenClass({
positionalParams: ['action']
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
{{#debounce-action (action (mut appName) 'XXX') after=1000 as |delayedMut|}}
<button {{action delayedMut on='click'}}>
Change appName after 1 second
</button>
{{/debounce-action}}
{
"version": "0.13.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment