Skip to content

Instantly share code, notes, and snippets.

@thousand
Last active April 26, 2018 02:59
Show Gist options
  • Select an option

  • Save thousand/bacdfc3c420da9fb3993b73c5e03df76 to your computer and use it in GitHub Desktop.

Select an option

Save thousand/bacdfc3c420da9fb3993b73c5e03df76 to your computer and use it in GitHub Desktop.
action in an action
import Ember from 'ember';
export default Ember.Component.extend({
init() {
this._super(...arguments);
this.set('toggle', (f) => {
f();
});
}
});
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<p>"two in one"</p>
{{#comp-one as |cp1|}}
{{#comp-two as |cp2|}}
<button {{action cp1.toggle cp2.toggle}}>Toggle</button>
{{/comp-two}}
{{/comp-one}}
<hr>
<p>"one in two"</p>
{{#comp-two as |cp1|}}
{{#comp-one as |cp2|}}
<button {{action cp1.toggle cp2.toggle}}>Toggle</button>
{{/comp-one}}
{{/comp-two}}
<br>
{{outlet}}
<br>
<br>
<h2>Component One</h2>
{{yield (hash toggle=toggle)}}
<h3>Component Two</h3>
{{#if enabled}}
<p>Totes ON</p>
{{else}}
<p>Totes off</p>
{{/if}}
{{yield (hash toggle=(action (mut enabled) (if enabled false true))) }}
{
"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