Skip to content

Instantly share code, notes, and snippets.

@averydev
Last active June 25, 2016 01:02
Show Gist options
  • Save averydev/02b2640c772ec09c8ca8939a0de36940 to your computer and use it in GitHub Desktop.
Save averydev/02b2640c772ec09c8ca8939a0de36940 to your computer and use it in GitHub Desktop.
DDAU Input Field Pattern
import Ember from 'ember';
const {computed} = Ember;
export default Ember.Component.extend({
sourceProperty:null,
proxyProperty:computed('sourceProperty', {
get(key){
return this.get('sourceProperty');
},
set(key, value){
this.get('updateTestProperty')(value);
return value;
}
}),
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
testProperty:"initialValue",
actions: {
updateTestProperty(newValue){
this.set('testProperty', newValue);
}
}
});
<p>The idea here is to have an input bound to the value of a source property, with the convenience of just setting the `value` of an `input` while using DDAU to a parent to actually do the setting of the property in question.</p>
<h3> Application Template </h3>
testProperty = {{testProperty}}<br>
<hr>
{{input-component updateTestProperty=(action 'updateTestProperty')
sourceProperty=testProperty}}
{{outlet}}
<br>
<br>
<h3> Input Component </h3>
{{input value=proxyProperty}}<br>
proxyProperty = {{proxyProperty}}
{{yield}}
{
"version": "0.9.3",
"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.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment