nixos-configs/modules/ags/gtk4/widget/astalify/bindings.ts
matt1432 c3c4054793
All checks were successful
Discord / discord commits (push) Has been skipped
refactor(ags4): split up astalify code
2025-01-14 10:12:20 -05:00

27 lines
692 B
TypeScript

import { Variable } from 'astal';
import { Binding } from 'astal/binding';
export const mergeBindings = <Value = unknown>(
array: (Value | Binding<Value> | Binding<Value[]>)[],
): Value[] | Binding<Value[]> => {
const getValues = (args: Value[]) => {
let i = 0;
return array.map((value) => value instanceof Binding ?
args[i++] :
value);
};
const bindings = array.filter((i) => i instanceof Binding);
if (bindings.length === 0) {
return array as Value[];
}
if (bindings.length === 1) {
return (bindings[0] as Binding<Value[]>).as(getValues);
}
return Variable.derive(bindings, getValues)();
};