Skip to content

Lifecycle hook upon asyncReplace update or completion #2219

Answered by justinfagnani
lpellegr asked this question in Q&A
Discussion options

You must be logged in to vote

This is one reason why reactive controllers are in some ways a more powerful tool to handle async values than until and asyncReplate. The downside is that controllers trigger entire component updates (which is the point here - so you can tie into the update lifecycle) whereas directives update only one binding in a template. You could make a reactive controller to use instead of asyncReplace.

This is untested, but roughly the idea:

class AsyncValue implements ReactiveController {
  private _host: ReactiveControllerHost;  
  private _iterable?: AsyncIterable<T>;
  private _cancelIteration?: () => void;
  
  value?: T;
  
  set iterable(v?: AsyncIterable<T>) {
    if (this._iterable !== v) {

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lpellegr
Comment options

Answer selected by lpellegr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants