Skip to content

Instantly share code, notes, and snippets.

@Panman82
Created January 3, 2017 21:34
Show Gist options
  • Save Panman82/41da78414b88e3c514f7fc3a76f0a9ad to your computer and use it in GitHub Desktop.
Save Panman82/41da78414b88e3c514f7fc3a76f0a9ad to your computer and use it in GitHub Desktop.
Register Child Components for Communication
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'li',
isExpanded: true,
registerItem: 'registerItem',
init(){
this._super( ...arguments );
this.sendAction('registerItem', this);
},
click(){
this.toggleProperty('isExpanded');
},
actions: {
expand(){
this.set('isExpanded', true);
},
collapse(){
this.set('isExpanded', false);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
deprecationItems: [],
deprecations: [
'foo',
'bar',
'baz'
],
actions: {
registerItem(component) {
this.get('deprecationItems').pushObject(component);
},
expandAll() {
this.get('deprecationItems').forEach(component => {
component.send('expand');
});
},
collapseAll() {
this.get('deprecationItems').forEach(component => {
component.send('collapse');
});
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<button {{action "expandAll"}}>Expand All</button>
<button {{action "collapseAll"}}>Collapse All</button>
<br>
<ul>
{{#each deprecations as |deprecation|}}
{{#deprecation-item}}
{{deprecation}}
{{/deprecation-item}}
{{/each}}
</ul>
{{yield}} - {{if isExpanded "Expanded" "Collapsed"}}
{
"version": "0.10.7",
"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.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment