@ethlete/query 0.1.0-next.3 → 0.1.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -891,6 +891,7 @@ const skipPaginationPageParamCalculator = ({ page, itemsPerPage }) => itemsPerPa
891
891
  const INFINITY_QUERY_TOKEN = new InjectionToken('INFINITY_QUERY_TOKEN');
892
892
  class InfinityQueryDirective {
893
893
  constructor() {
894
+ this._queryConfigChanged$ = new Subject();
894
895
  this._viewContext = {
895
896
  $implicit: null,
896
897
  infinityQuery: null,
@@ -909,12 +910,14 @@ class InfinityQueryDirective {
909
910
  this._viewContainerRef = inject(ViewContainerRef);
910
911
  this._mainTemplateRef = inject((TemplateRef));
911
912
  this._errorHandler = inject(ErrorHandler);
913
+ this._data$ = new BehaviorSubject([]);
912
914
  this._isMainViewCreated = false;
913
915
  }
914
916
  get infinityQuery() {
915
917
  return this._infinityQuery;
916
918
  }
917
919
  set infinityQuery(v) {
920
+ this._cleanup();
918
921
  this._infinityQuery = v;
919
922
  this._infinityQueryInstance = this._setupInfinityQuery(v);
920
923
  this._loadNextPage();
@@ -925,6 +928,12 @@ class InfinityQueryDirective {
925
928
  get instance() {
926
929
  return this._infinityQueryInstance;
927
930
  }
931
+ get data$() {
932
+ return this._data$.asObservable();
933
+ }
934
+ get data() {
935
+ return this._data$.getValue();
936
+ }
928
937
  static ngTemplateContextGuard(dir, ctx) {
929
938
  return true;
930
939
  }
@@ -972,15 +981,17 @@ class InfinityQueryDirective {
972
981
  this._viewContext.currentPage = null;
973
982
  this._viewContext.itemsPerPage = null;
974
983
  this._viewContext.totalPages = null;
984
+ this._data$.next([]);
975
985
  }
976
986
  this._cdr.markForCheck();
977
- }), takeUntil(this._destroy$))
987
+ }), takeUntil(this._destroy$), takeUntil(this._queryConfigChanged$))
978
988
  .subscribe();
979
989
  instance.data$
980
990
  .pipe(tap((data) => {
981
991
  this._viewContext.infinityQuery = this._viewContext.$implicit = data;
992
+ this._data$.next(data);
982
993
  this._cdr.markForCheck();
983
- }), takeUntil(this._destroy$))
994
+ }), takeUntil(this._destroy$), takeUntil(this._queryConfigChanged$))
984
995
  .subscribe();
985
996
  return instance;
986
997
  }
@@ -996,14 +1007,29 @@ class InfinityQueryDirective {
996
1007
  this._viewContainerRef.createEmbeddedView(this._mainTemplateRef, this._viewContext);
997
1008
  }
998
1009
  }
1010
+ _cleanup() {
1011
+ this._queryConfigChanged$.next(true);
1012
+ this.instance?._destroy();
1013
+ this._viewContext.loading = false;
1014
+ this._viewContext.error = null;
1015
+ this._viewContext.infinityQuery = null;
1016
+ this._viewContext.$implicit = null;
1017
+ this._viewContext.isFirstLoad = false;
1018
+ this._viewContext.canLoadMore = false;
1019
+ this._viewContext.currentPage = null;
1020
+ this._viewContext.itemsPerPage = null;
1021
+ this._viewContext.totalPages = null;
1022
+ this._data$.next([]);
1023
+ }
999
1024
  }
1000
1025
  InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: InfinityQueryDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1001
- InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.9", type: InfinityQueryDirective, isStandalone: true, selector: "[infinityQuery]", inputs: { infinityQuery: "infinityQuery" }, providers: [{ provide: INFINITY_QUERY_TOKEN, useExisting: InfinityQueryDirective }], ngImport: i0 });
1026
+ InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.9", type: InfinityQueryDirective, isStandalone: true, selector: "[infinityQuery]", inputs: { infinityQuery: "infinityQuery" }, providers: [{ provide: INFINITY_QUERY_TOKEN, useExisting: InfinityQueryDirective }], exportAs: ["infinityQuery"], ngImport: i0 });
1002
1027
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: InfinityQueryDirective, decorators: [{
1003
1028
  type: Directive,
1004
1029
  args: [{
1005
1030
  // eslint-disable-next-line @angular-eslint/directive-selector
1006
1031
  selector: '[infinityQuery]',
1032
+ exportAs: 'infinityQuery',
1007
1033
  standalone: true,
1008
1034
  providers: [{ provide: INFINITY_QUERY_TOKEN, useExisting: InfinityQueryDirective }],
1009
1035
  }]