Merge remote-tracking branch 'origin/bugfix/observer-should-resubscripe-if-hostdisconnected' into feature/modal-routing
This commit is contained in:
@@ -22,8 +22,4 @@ export class UmbObserverController<T = unknown> extends UmbObserver<T> implement
|
||||
|
||||
host.addController(this);
|
||||
}
|
||||
|
||||
hostConnected() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user