Closed willviles closed 5 years ago
We definitely should support encapsulated tasks. Thank you for raising the issue!
In order to reduce the amount of different decorators, ideally all existing @task
decorators would also be usable for encapsulated tasks. We can use the different syntactical constructs to differentiate between regular and encapsulated tasks, as you suggested.
import { dropTask } from 'ember-concurrency-decorators'
class Foo {
@dropTask
regularDropTask = function*() {
...
};
@dropTask
encapsulatedDropTask = {
somePrivateState: true,
*perform() {
...
}
};
}
Implementation should be pretty straightforward. We just change this assertion to allow objects with a perform
generator method on them as well.
What do you think?
I am also open to alternative API suggestions.
We could potentially add an @encapsulate
decorator (for lack of a better name) instead like:
import { dropTask, encapsulate } from 'ember-concurrency-decorators'
class Foo {
@dropTask
regularDropTask = function*() {
...
};
@dropTask
@encapsulate({
somePrivateState: true
})
encapsulatedDropTask = function*() {
...
};
}
The reason being, that this could potentially look nicer with the soon supported generator method syntax:
import { dropTask, encapsulate } from 'ember-concurrency-decorators'
class Foo {
@dropTask
*regularDropTask() {
...
}
@dropTask
@encapsulate({
somePrivateState: true
})
*encapsulatedDropTask() {
...
}
}
Wow, super speedy PR! Thanks @buschtoens.
I think it's probably overkill to introduce a secondary decorator. Just supplying an object is definitely the cleanest solution.
Just wondering if there's any planned support (or workaround) for encapsulated tasks?
The following raises the error:
Assertion Failed: ember-concurrency-decorators: Can only decorate a generator function as a task.
Perhaps the following syntax could work for a new decorator?