Skip to content

Instantly share code, notes, and snippets.

@willrax
Last active September 22, 2016 08:05
Show Gist options
  • Save willrax/a5dc64398c6a4cf912b5418fa333b078 to your computer and use it in GitHub Desktop.
Save willrax/a5dc64398c6a4cf912b5418fa333b078 to your computer and use it in GitHub Desktop.
properties
import Ember from 'ember';
const { computed } = Ember;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
model: {
name: 'will'
},
shadowValue: computed('model.name', {
get() {
return this.get('model.name');
},
set(_, value) {
return value;
}
}),
oneWayValue: computed.oneWay('model.name'),
actions: {
updateOneWay(value) {
this.set('oneWayValue', value);
},
updateShadow(value) {
this.set('shadowValue', value);
},
updateTwoWay(value) {
this.set('model.name', value);
},
reset() {
this.notifyPropertyChange('model.name');
},
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
Two Way Binding
<p>
value: {{model.name}}
</p>
<input oninput={{action "updateTwoWay" value="target.value"}}>
<br>
<br>
Shadow Property
<p>
value: {{shadowValue}}
</p>
<input oninput={{action "updateShadow" value="target.value"}}>
<br>
<br>
One Way Binding
<p>
value: {{oneWayValue}}
</p>
<input oninput={{action "updateOneWay" value="target.value"}}>
<br>
<br>
<button {{action "reset"}}>
Cancel
</button>
{
"version": "0.10.5",
"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.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment