Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pixelhandler/5e4297f9ae9c15ffe44d222bb1fc0ae6 to your computer and use it in GitHub Desktop.
Save pixelhandler/5e4297f9ae9c15ffe44d222bb1fc0ae6 to your computer and use it in GitHub Desktop.
Task with links disable when running
import Ember from 'ember';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
export default Ember.Controller.extend({
shared: service(),
task: alias('shared.doSomething')
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('foo');
this.route('bar');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
shared: Ember.inject.service(),
model() {
return Ember.get(this, 'shared.doSomething').perform();
}
});
import Ember from 'ember';
export default Ember.Route.extend({
shared: Ember.inject.service(),
model() {
return Ember.get(this, 'shared.doSomething').perform();
}
});
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
export default Ember.Service.extend({
doSomething: task(function*() {
yield timeout(1000);
}).drop().debug()
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
a.disabled {
opacity: .5;
}
<div>Task state: {{shared.doSomething.state}}</div>
<p>
Transition between the two routes before the task finishes to see the issue.
</p>
<br>
<br>
{{#link-to "foo" disabled=task.isRunning}}Foo{{/link-to}}
{{#link-to "bar" disabled=task.isRunning}}Bar{{/link-to}}
<br>
<br>
{{outlet}}
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0",
"ember-concurrency": "0.8.19"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment