1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Added function to run inside angular zone

This commit is contained in:
gbubemismith
2023-08-23 18:00:30 -04:00
parent 69a7b50b07
commit a512563f4e

View File

@@ -0,0 +1,21 @@
import { NgZone } from "@angular/core";
import { MonoTypeOperatorFunction, Observable } from "rxjs";
export function runInsideAngular<T>(ngZone: NgZone): MonoTypeOperatorFunction<T> {
return (source: Observable<T>) =>
new Observable<T>((subscriber) => {
const subscription = source.subscribe({
next(value) {
ngZone.run(() => subscriber.next(value));
},
error(error: unknown) {
ngZone.run(() => subscriber.error(error));
},
complete() {
ngZone.run(() => subscriber.complete());
},
});
return () => subscription.unsubscribe();
});
}