Skip to content

Instantly share code, notes, and snippets.

@jrode
Forked from FilmKnurd/components.my-debounce.js
Last active May 2, 2016 16: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 jrode/2e18e32685a8c1aec7798b4e9acbcc69 to your computer and use it in GitHub Desktop.
Save jrode/2e18e32685a8c1aec7798b4e9acbcc69 to your computer and use it in GitHub Desktop.
Debounce Test
import Ember from 'ember';
export default Ember.Component.extend({
_items: [],
inputVal: 'hello',
outputVal: 'hello',
pushIt: function() {
this.get('_items').pushObject('Hi ' + Date.now());
},
updateOutput: function() {
this.set('outputVal', this.get('inputVal'));
},
actions: {
delayit: function() {
Ember.run.debounce(this, 'pushIt', 2000);
},
updateVal: function() {
Ember.run.debounce(this, 'updateOutput', 500);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-debounce}}
<br>
<br>
{{input input=(action "updateVal") value=inputVal}}
<p>{{outputVal}}</p>
<br><br>
<button {{action 'delayit'}}>Add an Item</button>
<br>
<ul>
{{#each _items as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment