How to bind to more than 1 ReactFX observable?

167 views Asked by At

In regular JavaFX i would create a binding on 2 or more observables like this:

xxxProperty().bind(Bindings.createObjectBinding(() -> {...}, observable1, observable2, ...));

In ReactFx I was shown that I can create a binding like this:

xxxProperty().bind(val.map(value -> {...}));

but how do i create a binding on 2 or more ReactFX observables (Val and/or Var)?

1

There are 1 answers

5
Tomas Mikula On BEST ANSWER

For the general case, use one of these:

static <T> Val<T> create(Supplier<? extends T> computeValue, EventStream<?> invalidations)
static <T> Val<T> create(Supplier<? extends T> computeValue, Observable... dependencies)

For combining 2-6 values, there are convenience methods provided:

static <A,B,R> Val<R> combine(ObservableValue<A> src1, ObservableValue<B> src2, BiFunction<? super A,? super B,? extends R> f)
static <A,B,C,R> Val<R> combine(ObservableValue<A> src1, ObservableValue<B> src2, ObservableValue<C> src3, TriFunction<? super A,? super B,? super C,? extends R> f)
static <A,B,C,D,R> Val<R> combine(ObservableValue<A> src1, ObservableValue<B> src2, ObservableValue<C> src3, ObservableValue<D> src4, TetraFunction<? super A,? super B,? super C,? super D,? extends R> f)
static <A,B,C,D,E,R> Val<R> combine(ObservableValue<A> src1, ObservableValue<B> src2, ObservableValue<C> src3, ObservableValue<D> src4, ObservableValue<E> src5, PentaFunction<? super A,? super B,? super C,? super D,? super E,? extends R> f)
static <A,B,C,D,E,F,R> Val<R> combine(ObservableValue<A> src1, ObservableValue<B> src2, ObservableValue<C> src3, ObservableValue<D> src4, ObservableValue<E> src5, ObservableValue<F> src6, HexaFunction<? super A,? super B,? super C,? super D,? super E,? super F,? extends R> f)

All of these are static methods on Val.