Closed b0o closed 5 months ago
Hello @b0o! For this specific case, I recommend using the combine_latest
operator (I fixed it in #24). This will allow you to combine signal values from signal.foo
, signal.bar
, and signal.qux
. Here's an example code snippet:
n.paragraph({
is_focusable = false,
-- This is the important part:
lines = signal.foo:combine_latest(signal.bar, signal.qux, function(foo, bar, qux)
return {
n.line(n.text("Foo: ", "Keyword"), tostring(foo)),
n.line(n.text("Bar: ", "Keyword"), tostring(bar)),
n.line(n.text("Qux: ", "Keyword"), tostring(qux)),
}
end),
}),
I recommend using combine_latest
instead of mapping over the signal because mapping may cause unnecessary rerenders. Feel free to let me know if you have any other questions.
Oh that is really cool, thank you! I think some more examples in the Signal docs would be really helpful in understanding the use-cases of the different methods, like this.
I often find myself wanting to use several different signal values in a single prop. I'm currently doing something like this:
In the above example, although I'm mapping over the
foo
signal value, the function seems to be called when any of the signal's values change. In fact, it seems we can map over any signal field, even if it doesn't exist, likesignal.baz:map(fn)
.My request: It would be nice to be able to map directly over the signal,
signal:map(fn)
. The functionfn
should be called with the full value of the signal as the argument whenever any of the signal’s values change: