Fixing bug where subscribers are skipped, when subscriber unsubscribes directly
This commit is contained in:
@ -18,8 +18,7 @@ export default class AwaitStore<T = any> {
|
||||
|
||||
subscribe(handler: ObserverCallback<T>) {
|
||||
handler(this._value);
|
||||
this.observable.subscribe(handler);
|
||||
return () => this.unsubscribe(handler);
|
||||
return this.observable.subscribe(handler);
|
||||
}
|
||||
|
||||
unsubscribe(handler: ObserverCallback<T>) {
|
||||
@ -34,23 +33,11 @@ export default class AwaitStore<T = any> {
|
||||
const cb = () => {
|
||||
if (this._value === val) {
|
||||
yes();
|
||||
this.observable.unsubscribe(cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if (this._value === val) {
|
||||
yes();
|
||||
} else {
|
||||
ignore = () => {
|
||||
this.observable.unsubscribe(cb);
|
||||
}
|
||||
if (!cb()) {
|
||||
this.observable.subscribe(cb);
|
||||
this.unsubscribe(cb);
|
||||
}
|
||||
}
|
||||
|
||||
this.subscribe(cb);
|
||||
});
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user