parent
8bd0b732e7
commit
557e4c7a52
32 changed files with 281 additions and 12 deletions
modules/ags/gtk4/widgets/astalify
27
modules/ags/gtk4/widgets/astalify/bindings.ts
Normal file
27
modules/ags/gtk4/widgets/astalify/bindings.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
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)();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue