I haven’t exactly run into this scenario just yet but was thinking about while writing a controller:
export default class extends Controller {
public connected() {
fetch("/whatever").
then((response) => response.text()).
then((text) => {
// Do something with this.element
});
}
}
For setTimeout or setInterval, I can cancel the timeout or the interval in the disconnect callback. But for fetch, are we expected to cancel the fetch in the disconnect callback as well? I’m not entirely sure how to do that (using what-wg), but beyond this example, are there situations where you’re in a async callback that is after this.element is disconnected? If that’s the case, would it be helpful to have a variable/method to call to get the state of the controller (whether it’s connected or disconnected)?