move waitFor and get to BaseObservableValue

This commit is contained in:
Bruno Windels 2020-10-06 18:04:34 +02:00
parent b8dcb249ff
commit 514095da7a
2 changed files with 12 additions and 9 deletions

View file

@ -25,6 +25,17 @@ export class BaseObservableValue extends BaseObservable {
} }
} }
get() {
throw new Error("unimplemented");
}
waitFor(predicate) {
if (predicate(this.get())) {
return new ResolvedWaitForHandle(Promise.resolve(this.get()));
} else {
return new WaitForHandle(this, predicate);
}
}
} }
class WaitForHandle { class WaitForHandle {
@ -81,14 +92,6 @@ export class ObservableValue extends BaseObservableValue {
this.emit(this._value); this.emit(this._value);
} }
} }
waitFor(predicate) {
if (predicate(this.get())) {
return new ResolvedWaitForHandle(Promise.resolve(this.get()));
} else {
return new WaitForHandle(this, predicate);
}
}
} }
export function tests() { export function tests() {

View file

@ -31,7 +31,7 @@ export class OnlineStatus extends BaseObservableValue {
this.emit(true); this.emit(true);
} }
get value() { get() {
return navigator.onLine; return navigator.onLine;
} }