Merge remote-tracking branch 'origin/bugfix/observer-should-resubscripe-if-hostdisconnected' into feature/modal-routing

This commit is contained in:
Niels Lyngsø
2023-03-15 20:20:25 +01:00
2 changed files with 9 additions and 8 deletions

View File

@@ -22,8 +22,4 @@ export class UmbObserverController<T = unknown> extends UmbObserver<T> implement
host.addController(this);
}
hostConnected() {
return;
}
}

View File

@@ -1,15 +1,20 @@
import { Observable, Subscription } from 'rxjs';
export class UmbObserver<T> {
#source!: Observable<T>;
#callback!: (_value: T) => void;
#subscription!: Subscription;
constructor(source: Observable<T>, callback: (_value: T) => void) {
this.#subscription = source.subscribe((value) => {
callback(value);
});
this.#source = source;
this.#subscription = source.subscribe(callback);
}
// Notice controller class implements empty hostConnected().
hostConnected() {
if (this.#subscription.closed) {
this.#subscription = this.#source.subscribe(this.#callback);
}
}
hostDisconnected() {
// No cause then it cant re-connect, if the same element just was moved in DOM.