diff options
author | Aylur <[email protected]> | 2024-07-31 13:55:17 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-07-31 13:55:17 +0200 |
commit | e398c9f997935d04835df387b6bc40bdf7a87910 (patch) | |
tree | 4591870438af6b0b40874f2414f1fa2d822555ce /gjs | |
parent | e56a7f5dcbf4573436b4aa12a6e48a5771df160c (diff) |
feat: optional Variable.derive transform
Diffstat (limited to 'gjs')
-rw-r--r-- | gjs/src/variable.ts | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/gjs/src/variable.ts b/gjs/src/variable.ts index 05e142f..d583ab1 100644 --- a/gjs/src/variable.ts +++ b/gjs/src/variable.ts @@ -195,13 +195,14 @@ class VariableWrapper<T> extends Function { return this as unknown as Variable<T> } - static derive<V, + static derive< const Deps extends Array<Variable<any> | Binding<any>>, Args extends { [K in keyof Deps]: Deps[K] extends Variable<infer T> ? T : Deps[K] extends Binding<infer T> ? T : never }, - >(deps: Deps, fn: (...args: Args) => V) { + V = Args, + >(deps: Deps, fn: (...args: Args) => V = (...args) => args as unknown as V) { const update = () => fn(...deps.map(d => d.get()) as Args) const derived = new Variable(update()) const unsubs = deps.map(dep => dep.subscribe(() => derived.set(update()))) |