machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
691 stars 157 forks source link

Can't access property "lastSuccessful", this[taskName] is undefined #420

Closed esbanarango closed 3 years ago

esbanarango commented 3 years ago

🐞 Describe the Bug

When using the @lastValue decorator and passing the path of a task. There is an error:

Note: This was working before with ember-concurrency-decorators.

🔬 Minimal Reproduction

export default class MyService extends Service {
  @dropTask
  *myTask() {
    yield null;
  };
}
import { lastValue } from 'ember-concurrency';

export default class MyComponent extends Component {
  @service myService;
  @lastValue('myService.myTask') value;
}
Screen Shot 2021-04-08 at 8 08 30 PM

🌍 Environment

maxfierke commented 3 years ago

Thanks for the heads up about this! I've opened a PR to document this as something that's been removed in ember-concurrency v2, as restoring the behavior would rely on using Ember.get or implementing our own support for chained property access here. I think the recommendation would be to refactor this so that it can read a property directly on the component, e.g.:

import { lastValue } from 'ember-concurrency';

export default class MyComponent extends Component {
  @service myService;
  get myServiceTask() { return this.myService.myTask; }
  @lastValue('myServiceTask') value;
}

Or otherwise, you could put the lastValue on the class as a property if you're reading it a lot / don't need to expose components to the task:

import { lastValue } from 'ember-concurrency';

export default class MyService extends Service {
  @dropTask
  *myTask() {
    yield null;
  };
  @lastValue('myTask') myTaskValue;
}