Commit dcba2b09 authored by Merzough Münker's avatar Merzough Münker
Browse files

feat(DataSourceDirective): run template creation in zone

parent 4194c58f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
# Changelog

## [0.6.0]
### Changed
- (DataSourceDirective): run template creation in zone

## [0.5.2]
### Added
- fix viewer is issue
+24 −8
Original line number Diff line number Diff line
@@ -8,7 +8,9 @@ import {
  OnDestroy,
  ChangeDetectorRef,
  OnChanges,
  SimpleChanges
  SimpleChanges,
  NgZone,
  EmbeddedViewRef
} from '@angular/core';
import {
  DataSourceLoader,
@@ -16,7 +18,10 @@ import {
  BaseDataSourceViewer
} from '@rxap/data-source';
import { Required } from '@rxap/utilities';
import { tap } from 'rxjs/operators';
import {
  tap,
  take
} from 'rxjs/operators';
import {
  Observable,
  Subscription
@@ -47,12 +52,15 @@ export class DataSourceDirective<Data = any> implements OnDestroy, OnChanges {

  protected readonly subscription = new Subscription();

  protected embeddedViewRef?: EmbeddedViewRef<DataSourceTemplate<Data>>;

  constructor(
    private readonly dataSourceLoader: DataSourceLoader,
    private readonly template: TemplateRef<DataSourceTemplate<Data>>,
    private readonly viewContainerRef: ViewContainerRef,
    private readonly injector: Injector,
    private readonly cdr: ChangeDetectorRef
    private readonly cdr: ChangeDetectorRef,
    private readonly zone: NgZone
  ) {
    this.viewer = this;
  }
@@ -81,16 +89,24 @@ export class DataSourceDirective<Data = any> implements OnDestroy, OnChanges {
    if (this.dataSource) {
      this.connection$ = this.dataSource
                             .connect(this.viewer);
      this.subscription.add(this.connection$.pipe(
        tap(response => this.embedTemplate(response))
                              )
      this.zone.onStable.pipe(
        take(1),
        tap(() => {
          this.zone.run(() => {
            this.subscription.add(this
              .connection$
              .pipe(tap(response => this.embedTemplate(response)))
              .subscribe());
          });
        })
      ).subscribe();

    }
  }

  public embedTemplate(response: any) {
    this.viewContainerRef.clear();
    this.viewContainerRef.createEmbeddedView(this.template, {
    this.embeddedViewRef?.destroy();
    this.embeddedViewRef = this.viewContainerRef.createEmbeddedView(this.template, {
      $implicit:   response,
      connection$: this.connection$
    });
+1 −1
Original line number Diff line number Diff line
{
  "name": "@rxap/data-source",
  "version": "0.5.2",
  "version": "0.6.0",
  "private": false,
  "author": "Merzough Münker",
  "homepage": "https://gitlab.com/rxap/packages",