Skip to content

Instantly share code, notes, and snippets.

@LeoBorai
Forked from jenweber/my-octane-component.js
Created May 18, 2020 18:56
Show Gist options
  • Select an option

  • Save LeoBorai/b1ec9127fd738d260522d14b132b1edb to your computer and use it in GitHub Desktop.

Select an option

Save LeoBorai/b1ec9127fd738d260522d14b132b1edb to your computer and use it in GitHub Desktop.
How to use Ember Concurrency with Octane
// 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;
};
// 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