@one-paragon/angular-utilities 2.3.3 → 2.3.4
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Input, Directive, inject, Injector, TemplateRef, ViewContainerRef, NgModule, assertInInjectionContext, DestroyRef, signal, computed, isSignal, InjectionToken, Injectable, runInInjectionContext, input, Renderer2, ElementRef, booleanAttribute, Pipe, makeEnvironmentProviders, ChangeDetectionStrategy, Component, HostListener, EventEmitter,
|
|
2
|
+
import { Input, Directive, inject, Injector, TemplateRef, ViewContainerRef, NgModule, assertInInjectionContext, DestroyRef, signal, computed, isSignal, effect, untracked, InjectionToken, Injectable, runInInjectionContext, input, Renderer2, ElementRef, booleanAttribute, Pipe, makeEnvironmentProviders, ChangeDetectionStrategy, Component, HostListener, EventEmitter, Output, ContentChildren, ChangeDetectorRef, output, viewChild, EnvironmentInjector, createComponent, linkedSignal, contentChild, forwardRef, contentChildren, provideAppInitializer } from '@angular/core';
|
|
3
3
|
import { shareReplay, map, switchAll, filter, tap, catchError, startWith, switchMap, mergeMap, concatMap as concatMap$1, takeUntil, distinctUntilChanged, debounceTime } from 'rxjs/operators';
|
|
4
4
|
import * as i1 from 'rxjs';
|
|
5
5
|
import { isObservable, Subject, of, ReplaySubject, filter as filter$1, first, map as map$1, Observable, combineLatest, Subscription, startWith as startWith$1, pairwise, pipe, concatMap, merge, delay, fromEvent, takeUntil as takeUntil$1, tap as tap$1, switchMap as switchMap$1, scan, timestamp } from 'rxjs';
|
|
@@ -594,6 +594,10 @@ class RequestStateStore {
|
|
|
594
594
|
* @deprecated use the standalone subscriber helper function
|
|
595
595
|
*/
|
|
596
596
|
this.on = this.subscriber;
|
|
597
|
+
/**
|
|
598
|
+
* @param params An observable or signal that returns an array to be spread into the request function.
|
|
599
|
+
* If undefined is returned, the request will not be made.
|
|
600
|
+
*/
|
|
597
601
|
this.requestWith = (params) => {
|
|
598
602
|
if (isSignal(params)) {
|
|
599
603
|
params = toObservable(params, { injector: this.injector }).pipe(notNull());
|
|
@@ -601,6 +605,32 @@ class RequestStateStore {
|
|
|
601
605
|
params.pipe(takeUntil(this.destroy$)).subscribe((p) => this.request(...p));
|
|
602
606
|
return this;
|
|
603
607
|
};
|
|
608
|
+
/**
|
|
609
|
+
* @param params The parameters to be passed to the request function.
|
|
610
|
+
* The parameters can be either actual values or wrapped in a signal.
|
|
611
|
+
* If any of the parameters are a signal, it will be unwrapped and passed to the request.
|
|
612
|
+
* It will be tracked and the request will be made whenever its value changes.
|
|
613
|
+
* If any of the signals return undefined, the request will not be made.
|
|
614
|
+
*/
|
|
615
|
+
this.requestOn = (...params) => {
|
|
616
|
+
const paramsArr = computed(() => {
|
|
617
|
+
const p = params.map(param => isSignal(param)
|
|
618
|
+
? ({ param, isSignal: true })
|
|
619
|
+
: ({ param, isSignal: false }));
|
|
620
|
+
const allVals = p.every(({ param, isSignal }) => !isSignal || param() != undefined);
|
|
621
|
+
if (allVals)
|
|
622
|
+
return p.map(({ param, isSignal }) => isSignal ? param() : param);
|
|
623
|
+
return undefined;
|
|
624
|
+
});
|
|
625
|
+
effect(() => {
|
|
626
|
+
const vals = paramsArr();
|
|
627
|
+
untracked(() => {
|
|
628
|
+
if (vals)
|
|
629
|
+
this.request(...vals);
|
|
630
|
+
});
|
|
631
|
+
}, { injector: this.injector });
|
|
632
|
+
return this;
|
|
633
|
+
};
|
|
604
634
|
this.assertInjectionContext();
|
|
605
635
|
this.injector.get(DestroyRef).onDestroy(() => this.destroy$.next());
|
|
606
636
|
this.project = project;
|
|
@@ -688,6 +718,7 @@ class RequestStateStore {
|
|
|
688
718
|
class CancellationToken {
|
|
689
719
|
}
|
|
690
720
|
/**
|
|
721
|
+
* @param sigOrObs An array of signals or observables to be wrapped in an array to be spread into the request function.
|
|
691
722
|
* If any values from the array of signals or observables are null or undefined, all values will be filtered
|
|
692
723
|
*/
|
|
693
724
|
function wrapInArr(...sigOrObs) {
|