mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
Added function to run inside angular zone
This commit is contained in:
21
libs/angular/src/utils/run-inside-angular.operator.ts
Normal file
21
libs/angular/src/utils/run-inside-angular.operator.ts
Normal 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();
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user