Skip to content

RFC: re-envision Encapsulated Tasks #466

Open
@machty

Description

@machty

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
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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions