Skip to content

Instantly share code, notes, and snippets.

@jgwhite
Last active July 22, 2020 09:09
Show Gist options
  • Save jgwhite/a7f9530d610b9767d177f15416a3fff6 to your computer and use it in GitHub Desktop.
Save jgwhite/a7f9530d610b9767d177f15416a3fff6 to your computer and use it in GitHub Desktop.
Modifier Forwarding Demo
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
@tracked actionClicked = false;
@tracked onclickClicked = false;
@tracked onClicked = false;
@action enable(prop) {
this[prop] = true;
}
}
<p>
<CoolButton
{{action this.enable "actionClicked"}}
>
\{{action this.enable "actionClicked"}}
</CoolButton>
{{#if this.actionClicked}}clicked!{{/if}}
</p>
<p>
<CoolButton
onclick={{action this.enable "onclickClicked"}}
>
onclick=\{{action this.enable "onclickClicked"}}
</CoolButton>
{{#if this.onclickClicked}}clicked!{{/if}}
</p>
<p>
<CoolButton
{{on "click" (fn this.enable "onClicked")}}
>
\{{on "click" (fn this.enable "onClicked")}}
</CoolButton>
{{#if this.onClicked}}clicked!{{/if}}
</p>
<button
style="
font-family: monospace;
display: inline-flex;
align-items: center;
padding: 4px 12px;
"
...attributes
>
<span
style="
margin-right: 4px
"
aria-hidden
>
😎
</span>
{{yield}}
</button>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true,
"_APPLICATION_TEMPLATE_WRAPPER": false,
"_JQUERY_INTEGRATION": false
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"ember": "3.11.1",
"ember-template-compiler": "3.11.1",
"ember-testing": "3.11.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment