diff options
-rw-r--r-- | src/observable.ts | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/observable.ts b/src/observable.ts index a9e23e8..bd66963 100644 --- a/src/observable.ts +++ b/src/observable.ts @@ -41,6 +41,13 @@ export class OVar<T> { uv.weak = true return uv; } + liftA2<U, V>(other: OVar<U>, fn: (x: T, y: U) => V): OVar<V> { + const uv = new OVar(fn(this.value, other.value)) + uv.cancel_source = this.onchange(x => uv.value = fn(x, other.value)) + uv.cancel_source = other.onchange(y => uv.value = fn(this.value, y)) + uv.weak = true + return uv; + } wait_for(val: T) { return new Promise<void>(r => { const abort = this.onchangeinit(v => { |