Skip to content

Instantly share code, notes, and snippets.

@dwickern
Last active January 20, 2017 20:23
Show Gist options
  • Save dwickern/c0ab86f1570d5577b60c2e54e04a2bfe to your computer and use it in GitHub Desktop.
Save dwickern/c0ab86f1570d5577b60c2e54e04a2bfe to your computer and use it in GitHub Desktop.
input
import Ember from 'ember';
const DEBOUNCE_MILLIS = 300;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
value: 1,
displayText: function() {
return `current value is ${this.get('value')}!`;
}.property('value'),
debouncedSetValue(value) {
this.set('value', value);
},
actions: {
changed(e) {
this.set('value', e.target.value);
},
debounced(e) {
// http://emberjs.com/api/classes/Ember.run.html#method_debounce
Ember.run.debounce(this, this.debouncedSetValue, e.target.value, DEBOUNCE_MILLIS);
}
}
});
<h1>Welcome to {{appName}}</h1>
Two-way binding
{{input type="number" value=value}}
<br>
One-way binding
{{input type="number" value=(readonly value)}}
<br>
One-way binding + change event
{{input type="number" value=(readonly value) change=(action "changed")}}
<br>
One-way binding + input event
{{input type="number" value=(readonly value) input=(action "changed")}}
<br>
One-way binding + debounced input event
{{input type="number" value=(readonly value) input=(action "debounced")}}
<br>
<br>
{{displayText}}
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment