Last active
May 27, 2021 16:08
-
-
Save jenweber/443dac9876c7ef2b1115093cfd5d6fac 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(', ')}`); | |
}), | |
}); | |
<button type="button" {{on "click" (perform callAction)}}>Save</button>
- this is how I call perform and it works
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @jenweber
I use ember-concurrency with ember octane. can you explain with handlebars?
I try to set
pickRandomNumbers
on button.but it can't work. So, I add
@action
decorator with taskIt can't work too.
Finally I use action for call perform task
It works. but how can I use
perform
keyword withon
?