Skip to content

Instantly share code, notes, and snippets.

@Juraci
Last active April 13, 2017 12:45
Show Gist options
  • Save Juraci/69ace3d4beca302a697d587cbb01f9c9 to your computer and use it in GitHub Desktop.
Save Juraci/69ace3d4beca302a697d587cbb01f9c9 to your computer and use it in GitHub Desktop.
Computed properties in components
import Ember from 'ember';
export default Ember.Component.extend({
messages: [],
alertAmount: Ember.computed('messages.length', function() {
return this.get('messages.length');
}),
init() {
this._super(...arguments);
setTimeout(() => {
if(this.get('sensor.enabled')) {
this.get('messages').pushObject('foo');
}
}, 1000);
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
model: [
Ember.Object.create({ enabled: true, description: 'living room'}),
Ember.Object.create({ enabled: false, description: 'bedroom'})
]
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#each model as |sensor|}}
{{sensor-item sensor=sensor}}
{{/each}}
<br>
<br>
<span>{{sensor.description}} - Activity {{alertAmount}} </span>
{
"version": "0.12.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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment