Previous: Type-Ahead Search
Next: AJAX Throttling
This example demonstrates a few different concepts:
(perform taskName) in place of anywhere you
might want to use a classic Ember action.
(Hold down the buttons to accelerate.)
export default class IncrementButtonsController extends Controller {
count = 0;
@task *incrementBy(inc) {
let speed = 400;
while (true) {
this.incrementProperty('count', inc);
yield timeout(speed);
speed = Math.max(50, speed * 0.8);
}
}
}
<p>
<PressAndHoldButton @press={{perform this.incrementBy -1}} @release={{cancel-all this.incrementBy}}>
--Decrease
</PressAndHoldButton>
<PressAndHoldButton @press={{perform this.incrementBy 1}} @release={{cancel-all this.incrementBy}}>
Increase++
</PressAndHoldButton>
</p>
<button
{{! template-lint-disable no-down-event-binding }}
{{on "touchstart" @press}}
{{on "mousedown" @press}}
{{on "touchend" @release}}
{{on "mouseleave" @release}}
{{on "mouseup" @release}}
type="button">
{{yield}}
</button>
Previous: Type-Ahead Search
Next: AJAX Throttling