@mmstack/resource 19.2.0 → 20.0.1

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.
package/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
  1. Install mmstack-resource
24
24
 
25
25
  ```bash
26
- npm install @mmstack/primitives
26
+ npm install @mmstack/resource
27
27
  ```
28
28
 
29
29
  2. Initialize the QueryCache & interceptors (optional)
@@ -1,4 +1,4 @@
1
- import { computed, untracked, InjectionToken, inject, isDevMode, signal, effect, linkedSignal, ResourceStatus, DestroyRef } from '@angular/core';
1
+ import { computed, untracked, InjectionToken, inject, isDevMode, signal, effect, linkedSignal, DestroyRef } from '@angular/core';
2
2
  import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
3
3
  import { of, tap, map, finalize, shareReplay, interval, firstValueFrom, combineLatestWith, filter } from 'rxjs';
4
4
  import { HttpContextToken, HttpContext, HttpResponse, HttpParams, httpResource, HttpClient } from '@angular/common/http';
@@ -755,9 +755,9 @@ function retryOnError(res, opt) {
755
755
  };
756
756
  const ref = effect(() => {
757
757
  switch (res.status()) {
758
- case ResourceStatus.Error:
758
+ case 'error':
759
759
  return onError();
760
- case ResourceStatus.Resolved:
760
+ case 'resolved':
761
761
  return onSuccess();
762
762
  }
763
763
  });
@@ -805,7 +805,9 @@ function queryResource(request, options) {
805
805
  return undefined;
806
806
  return request() ?? undefined;
807
807
  }, {
808
- equal: createEqualRequest(options?.equal),
808
+ equal: options?.triggerOnSameRequest
809
+ ? undefined
810
+ : createEqualRequest(options?.equal),
809
811
  });
810
812
  const hashFn = typeof options?.cache === 'object'
811
813
  ? (options.cache.hash ?? urlWithParams)
@@ -881,9 +883,9 @@ function queryResource(request, options) {
881
883
  // iterate circuit breaker state, is effect as a computed would cause a circular dependency (resource -> cb -> resource)
882
884
  const cbEffectRef = effect(() => {
883
885
  const status = resource.status();
884
- if (status === ResourceStatus.Error)
886
+ if (status === 'error')
885
887
  cb.fail();
886
- else if (status === ResourceStatus.Resolved)
888
+ else if (status === 'resolved')
887
889
  cb.success();
888
890
  });
889
891
  const set = (value) => {
@@ -1007,22 +1009,22 @@ function mutationResource(request, options = {}) {
1007
1009
  const value$ = toObservable(resource.value);
1008
1010
  const statusSub = toObservable(resource.status)
1009
1011
  .pipe(combineLatestWith(error$, value$), map(([status, error, value]) => {
1010
- if (status === ResourceStatus.Error && error) {
1012
+ if (status === 'error' && error) {
1011
1013
  return {
1012
- status: ResourceStatus.Error,
1014
+ status: 'error',
1013
1015
  error,
1014
1016
  };
1015
1017
  }
1016
- if (status === ResourceStatus.Resolved && value !== null) {
1018
+ if (status === 'resolved' && value !== null) {
1017
1019
  return {
1018
- status: ResourceStatus.Resolved,
1020
+ status: 'resolved',
1019
1021
  value,
1020
1022
  };
1021
1023
  }
1022
1024
  return null;
1023
1025
  }), filter((v) => v !== null), takeUntilDestroyed(destroyRef))
1024
1026
  .subscribe((result) => {
1025
- if (result.status === ResourceStatus.Error)
1027
+ if (result.status === 'error')
1026
1028
  onError?.(result.error, ctx);
1027
1029
  else
1028
1030
  onSuccess?.(result.value, ctx);