Skip to content

Instantly share code, notes, and snippets.

@givanse
Created September 1, 2017 09:42
Show Gist options
  • Save givanse/67d8b947f77f784ae689f02d37114153 to your computer and use it in GitHub Desktop.
Save givanse/67d8b947f77f784ae689f02d37114153 to your computer and use it in GitHub Desktop.
conditional closure action on contextual component
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['child_component'],
tagName: 'button',
actions: {
doSomething: function() {
alert('child: did something');
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['parent_component'],
isEnabled: false,
actions: {
doSomething: function() {
alert('parent: did something');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
doSomething: function() {
console.log('application: did something');
alert('application: did something');
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.parent_component {
background-color: #eee;
padding: 8px;
}
.child_component {
background-color: #ccc;
}
{{#parent-component isEnabled=true as |p|}}
{{#component p.childComponent
click=(if p.isEnabled (action "doSomething"))
message=(if p.isEnabled "Yes" "No")
}}
Am I child?
{{/component}}
{{/parent-component}}
<small>parent component</small>
<br><br>
{{yield (hash
isEnabled=isEnabled
childComponent=(component 'child-component')
)}}
{
"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.4.5",
"ember-template-compiler": "2.4.5",
"ember-testing": "2.4.5"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment