-
-
Save LeoBorai/b1ec9127fd738d260522d14b132b1edb to your computer and use it in GitHub Desktop.
How to use Ember Concurrency with Octane
This file contains hidden or 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
| // Octane | |
| import Component from '@glimmer/component'; | |
| import { tracked } from '@glimmer/tracking'; | |
| import { task } from 'ember-concurrency'; | |
| export default class MyOctaneComponent extends Component{ | |
| @tracked status = null | |
| @(task(function * () { | |
| let nums = []; | |
| for (let i = 0; i < 3; i++) { | |
| nums.push(Math.floor(Math.random() * 10)); | |
| } | |
| this.status = `My favorite numbers: ${nums.join(', ')}`; | |
| })) pickRandomNumbers; | |
| }; |
This file contains hidden or 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
| // classic component for comparison. See http://ember-concurrency.com/docs/task-function-syntax/ | |
| import Component from '@ember/component'; | |
| import { task } from 'ember-concurrency'; | |
| export default Component.extend({ | |
| status: null, | |
| pickRandomNumbers: task(function * () { | |
| let nums = []; | |
| for (let i = 0; i < 3; i++) { | |
| nums.push(Math.floor(Math.random() * 10)); | |
| } | |
| this.set('status', `My favorite numbers: ${nums.join(', ')}`); | |
| }), | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment