Skip to content

Commit

Permalink
Merge pull request #387 from TrinTragula/master
Browse files Browse the repository at this point in the history
Fixed progressInterceptor to work correctly inside effects #386
  • Loading branch information
MurhafSousli authored Jan 4, 2025
2 parents 4328ef8 + 6030606 commit 34477e6
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

1 comment on commit 34477e6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.