You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with signals to build a more complex UI, you often want to compute one signal from another. The resulting computed signal is then a read-only signal whose value changes whenever the original signal value changes. This already exists on the client side through useComputed(). I would like something similar on the Java side.
Describe the solution you'd like
One to one
For mapping a signal to another, I'd like a map() method, similar to the one found in Stream and Optional:
ValueSignal<String> myValue = newValueSignal<String>(null, String.class);
Signal<Boolean> hasMyValue = myValue.map(Objects::nonNull); // True whenever myValue contains a non-null value
The returned signal is read-only.
Many to one
For mapping multiple signals to one, I'd like something like this:
In this example, the computedSignal factory method takes two parameters: a Supplier that computes the value, and an array of signals that the computed signal depends on. Whenever any of the dependencies change, the computed signal is re-computed. If you can figure out a way of deducing the dependencies from the Supplier alone, it would be even better.
The returned signal is read-only.
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
You read my mind except that the type of a readonly signal should be just Signal<T> instead of ValueSignal<T>.
At the same time, it's usually more efficient with Hilla to do the computation on the client so that you don't need to send multiple related value updates from the server to the client.
Describe your motivation
When working with signals to build a more complex UI, you often want to compute one signal from another. The resulting computed signal is then a read-only signal whose value changes whenever the original signal value changes. This already exists on the client side through
useComputed()
. I would like something similar on the Java side.Describe the solution you'd like
One to one
For mapping a signal to another, I'd like a
map()
method, similar to the one found inStream
andOptional
:The returned signal is read-only.
Many to one
For mapping multiple signals to one, I'd like something like this:
In this example, the
computedSignal
factory method takes two parameters: aSupplier
that computes the value, and an array of signals that the computed signal depends on. Whenever any of the dependencies change, the computed signal is re-computed. If you can figure out a way of deducing the dependencies from theSupplier
alone, it would be even better.The returned signal is read-only.
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: