Skip to content

Instantly share code, notes, and snippets.

@schonstal
Created April 30, 2018 18:16
Show Gist options
  • Save schonstal/bdfd1049f9fafe6966a143fc633286d3 to your computer and use it in GitHub Desktop.
Save schonstal/bdfd1049f9fafe6966a143fc633286d3 to your computer and use it in GitHub Desktop.
computed example
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
a: Ember.Object.create({ b: 3 }),
c: Ember.computed('a', function() {
return this.get('a.b');
}),
d: Ember.computed('a', 'a.b', function() {
return this.get('a.b');
}),
actions: {
updateA() {
this.set('a', Ember.Object.create({
b: 5
}));
},
updateB() {
this.set('a.b', 7);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<h1>The value of 'a.b' is:</h1>
computed('a', ...: {{c}}
<br>
computed('a', 'a.b', ...: {{d}}
<br>
<button {{action "updateA"}}>set a</button>
<br>
<button {{action "updateB"}}>set a.b</button>
{{outlet}}
<br>
<br>
{
"version": "0.13.1",
"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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment