Open
Description
Placeholder RFC; TODO: add more details.
This is a design for a future API for encapsulated tasks that should be TS-friendly and support all of today's use cases for encapsulated tasks:
- We expose TaskInstance as a class that can be subclassed
- The same
task()
factory fn will accept the subclass as an arg - The host object will be accessible (and well-typed) as
this.context
- If you don't need access to the host obj (i.e. you are Very Encapsulated) then you can leave off the
<MyComponent>
type arg
- If you don't need access to the host obj (i.e. you are Very Encapsulated) then you can leave off the
class MyTaskInstance extends TaskInstance<MyComponent> {
@tracked counter = 0;
async perform(inc: number) {
while(true) {
await timeout(500);
this.counter += inc;
this.context.componentCounter += inc;
}
}
}
class MyComponent extends Component {
@tracked componentCounter = 0;
myTask = task({ drop:true }, MyTaskInstance);
}
// elsewhere: {{perform myTask 1}}, or this.myTask.perform(1)
Metadata
Metadata
Assignees
Labels
No labels