Skip to content

Commit

Permalink
Fixed progressInterceptor to work correctly inside effects
Browse files Browse the repository at this point in the history
  • Loading branch information
TrinTragula committed Dec 3, 2024
1 parent 1f38295 commit 2fd28f2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions projects/ngx-progressbar/http/src/ng-progress-http.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { inject, WritableSignal } from '@angular/core';
import { HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';
import { Observable, finalize } from 'rxjs';
import { NG_PROGRESS_HTTP_OPTIONS, NgProgressHttpOptions } from './ng-progress-http.model';
import { inject, untracked, WritableSignal } from '@angular/core';
import { finalize, Observable } from 'rxjs';
import { NgProgressHttpCounter } from './ng-progress-http-counter';
import { NG_PROGRESS_HTTP_OPTIONS, NgProgressHttpOptions } from './ng-progress-http.model';

export function progressInterceptor(req: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>> {

Expand All @@ -20,13 +20,15 @@ export function progressInterceptor(req: HttpRequest<unknown>, next: HttpHandler
return next(req);
}

inProgressCount.set(inProgressCount() + 1);
return untracked(() => {
inProgressCount.set(inProgressCount() + 1);

return next(req).pipe(
finalize(() => {
inProgressCount.set(inProgressCount() - 1);
})
);
return next(req).pipe(
finalize(() => {
inProgressCount.set(inProgressCount() - 1);
})
);
});
}


Expand Down

0 comments on commit 2fd28f2

Please sign in to comment.