Fixing bug where subscribers are skipped, when subscriber unsubscribes directly

This commit is contained in:
Fabian
2019-11-26 23:19:06 +01:00
parent 6720432e24
commit 811b03fd1b
4 changed files with 15 additions and 20 deletions

View File

@ -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 {