Skip to content

Instantly share code, notes, and snippets.

@jgwhite
Last active August 29, 2015 14:26
Show Gist options
  • Save jgwhite/c1905eafd87b5d798bcb to your computer and use it in GitHub Desktop.
Save jgwhite/c1905eafd87b5d798bcb to your computer and use it in GitHub Desktop.
Setter
import Ember from 'ember';
const { computed } = Ember;
export default Ember.Component.extend({
theValue: computed({
get() {
return this._theValue;
},
set(key, newValue) {
this._theValue = newValue;
return this._theValue;
}
}),
actions: {
change() {
this.set('theValue', 'goodbye');
}
}
});
{{my-component theValue="hello"}}
<p>The value is {{theValue}}</p>
<p><button {{action "change"}}>Change the value</button></p>
{
"version": "0.4.0",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.5/ember.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.5/ember-data.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment