How do i propagate change in my own Signals?

Hello, i am currently struggling with Signals. Here is my simple scenario:

I have a Canvas i want to hide onTap.

// first approach
let touched = R.val(false);
canvas.hidden = touched;
TG.onTap().subscribe(() => touched = R.val(true));

// second approach
const touched = R.boolSignalSource("id-touched");
canvas.hidden = touched.signal;
TG.onTap().subscribe(() => touched.set(true));

I bind the Canvas’ hidden field to my touched Signal.

Next i want to propagate a change to the touched Signal onTap.

The first approach doesn’t work. Does it destroy the binding to the original touched Signal onTap?

The second approach works, but it feels wrong to use. Also there are only 3 SignalSource types (bool, scalar, string)

I guess the core question is: how do i propagate change in my own Signals?

The first approach is overwriting the signal, so the one you listened to is not active any more, so it doesn’t fire any event.

The “Scripting Writeable Signal Source” is the only way to set values on signals, but you’re right that it’s a little limited. This is the correct way to do it, but you can also decouple your handler functions if you want to manually trigger them when you overwrite a signal. It’s not really in the reactive style, but you get more control over things.

Thank you for your answer.

This is what i ended up doing.

1 Like