benjamincharity
10/16/2019 - 6:16 PM

Merge events from a collection of child components

  public readonly headerCellResizes: Observable<TsHeaderCellResizeEvent> | Observable<{}> = defer(() => {
    if (this.headerCells && this.headerCells.length) {
      return merge(...this.headerCells.map(cell => cell.resized));
    }

    // If there are any subscribers before `ngAfterViewInit`, `headerCells` may be undefined.
    // In that case, return a stream that we'll replace with the real one once everything is in place.
    return this.ngZone.onStable
      .asObservable()
      .pipe(take(1), switchMap(() => this.headerCellResizes));
  });