Skip to content

Instantly share code, notes, and snippets.

@tomlagier
Created April 15, 2016 00:58
Show Gist options
  • Save tomlagier/6275ccd28b75c5f24d22c697049f291d to your computer and use it in GitHub Desktop.
Save tomlagier/6275ccd28b75c5f24d22c697049f291d to your computer and use it in GitHub Desktop.
Height toggle test, latest ember
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
baseItems: Ember.A(['red', 'blue','green']),
items: Ember.computed('baseItems.@each', function(){
return this.get('baseItems').map(item => {
return Ember.Object.create({
text: item,
heightToggled: false
});
});
}),
actions: {
click() {
this.get('items').forEach(childItem => {
childItem.toggleProperty('heightToggled');
});
},
addItem() {
this.get('baseItems').pushObject('yellow');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{parent-component}}
<br>
<br>
<li style="height: {{if item.heightToggled '100px' '50px'}}">{{item.text}}</li>
<button {{action 'click'}}>Toggle heights</button>
<button {{action 'addItem'}}>Add item</button>
{{#each items as |item|}}
{{child-component item=item}}
{{/each}}
{
"version": "0.7.2",
"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.4.4",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "2.4.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment