aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-29 11:14:32 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-29 11:14:32 +0100
commit17fbd41f033ca7aa11f91785904220ed509de1f3 (patch)
treebbaec68ca7121deb5b556b75acf7046133132efa
parentb7a3b1b81ed85c95ca8183407971aed724e3b9b2 (diff)
downloadjshelper-17fbd41f033ca7aa11f91785904220ed509de1f3.tar
jshelper-17fbd41f033ca7aa11f91785904220ed509de1f3.tar.bz2
jshelper-17fbd41f033ca7aa11f91785904220ed509de1f3.tar.zst
liftA2
-rw-r--r--src/observable.ts7
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 => {