@mmstack/resource 19.1.4 → 20.0.0

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
  });
@@ -881,9 +881,9 @@ function queryResource(request, options) {
881
881
  // iterate circuit breaker state, is effect as a computed would cause a circular dependency (resource -> cb -> resource)
882
882
  const cbEffectRef = effect(() => {
883
883
  const status = resource.status();
884
- if (status === ResourceStatus.Error)
884
+ if (status === 'error')
885
885
  cb.fail();
886
- else if (status === ResourceStatus.Resolved)
886
+ else if (status === 'resolved')
887
887
  cb.success();
888
888
  });
889
889
  const set = (value) => {
@@ -1007,22 +1007,22 @@ function mutationResource(request, options = {}) {
1007
1007
  const value$ = toObservable(resource.value);
1008
1008
  const statusSub = toObservable(resource.status)
1009
1009
  .pipe(combineLatestWith(error$, value$), map(([status, error, value]) => {
1010
- if (status === ResourceStatus.Error && error) {
1010
+ if (status === 'error' && error) {
1011
1011
  return {
1012
- status: ResourceStatus.Error,
1012
+ status: 'error',
1013
1013
  error,
1014
1014
  };
1015
1015
  }
1016
- if (status === ResourceStatus.Resolved && value !== null) {
1016
+ if (status === 'resolved' && value !== null) {
1017
1017
  return {
1018
- status: ResourceStatus.Resolved,
1018
+ status: 'resolved',
1019
1019
  value,
1020
1020
  };
1021
1021
  }
1022
1022
  return null;
1023
1023
  }), filter((v) => v !== null), takeUntilDestroyed(destroyRef))
1024
1024
  .subscribe((result) => {
1025
- if (result.status === ResourceStatus.Error)
1025
+ if (result.status === 'error')
1026
1026
  onError?.(result.error, ctx);
1027
1027
  else
1028
1028
  onSuccess?.(result.value, ctx);