-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6e6b61
commit 9d0ea3d
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
apps/tutorial/public/docs/3-event-handling/5-conditional-event-handling/answer.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { on } from '@ember/modifier'; | ||
|
||
export default class Incrementer extends Component { | ||
@tracked clicks = 0; | ||
@tracked enableIncrement = true; | ||
|
||
handleClick = () => this.clicks++; | ||
toggle = () => this.enableIncrement = !this.enableIncrement; | ||
|
||
<template> | ||
<button {{ (if this.enableIncrement (modifier on 'click' this.handleClick)) }}> | ||
Click me! | ||
</button> | ||
|
||
<button {{on 'click' this.toggle}}> | ||
Toggle Clicking | ||
</button> | ||
|
||
<br> | ||
Increment Enabled: {{this.enableIncrement}}<br> | ||
Clicked: {{this.clicks}} | ||
</template> | ||
} |
25 changes: 25 additions & 0 deletions
25
apps/tutorial/public/docs/3-event-handling/5-conditional-event-handling/prompt.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { on } from '@ember/modifier'; | ||
|
||
export default class Incrementer extends Component { | ||
@tracked clicks = 0; | ||
@tracked enableIncrement = true; | ||
|
||
handleClick = () => this.clicks++; | ||
toggle = () => this.enableIncrement = !this.enableIncrement; | ||
|
||
<template> | ||
<button {{on 'click' this.handleClick}}> | ||
Click me! | ||
</button> | ||
|
||
<button {{on 'click' this.toggle}}> | ||
Toggle Clicking | ||
</button> | ||
|
||
<br> | ||
Increment Enabled: {{this.enableIncrement}}<br> | ||
Clicked: {{this.clicks}} | ||
</template> | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/tutorial/public/docs/3-event-handling/5-conditional-event-handling/prose.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Events can be conditional by combining `if` syntax in _modifier space_. | ||
|
||
An important thing to keep in mind when writing conditional modifiers is the wrapping parenthesis: | ||
|
||
```hbs | ||
<button {{ (if condition (modifier on 'click' handleClick)) }}> | ||
Click me! | ||
</button> | ||
``` | ||
rather than | ||
```hbs | ||
<button {{if condition (modifier on 'click' handleClick)}}> | ||
runtime error! 'if' is not a modifier | ||
</button> | ||
``` | ||
|
||
|
||
This exercise has set up two buttons: one to increment a value when clicked, and one to enable incrementing of that value. | ||
|
||
<p class="call-to-play"> | ||
Adjust the code so that the toggle clicking button toggles the ability to increment the "Clicked" count. | ||
</p> |