componentDidMount()

in libs/core/src/lib/renderer/react-template.ts [73:98]


  componentDidMount() {
    const { context, ngZone, templateRef } = this.props;

    this._embeddedViewRef = templateRef.createEmbeddedView(context);
    const element = ReactDOM.findDOMNode(this);
    if (DEBUG) {
      console.warn('ReactTemplate Component > componentDidMount > childrenToAppend:', {
        rootNodes: this._embeddedViewRef.rootNodes,
      });
    }

    const hostElement = this.props.legacyRenderMode ? element : element.parentElement;

    this._embeddedViewRef.rootNodes.forEach(child => hostElement.appendChild(child));

    // Detect the first cycle's changes, and then subscribe for subsequent ones.
    this._embeddedViewRef.detectChanges();

    // Throttling the detect changes to an empirically selected value so we don't overload too much work.
    // TODO: This needs some better solution to listen to changes to the binding sources of the template.
    this._ngZoneSubscription = ngZone.onStable
      .pipe(throttleTime(TEMPLATE_DETECT_CHANGES_THROTTLE_MS, undefined, { leading: true, trailing: true }))
      .subscribe(() => {
        this._embeddedViewRef.detectChanges();
      });
  }