A question about Signals

There is something in the documentation that I am trying to understand (Design Patterns — JupyterLab 3.0.16 documentation).

It states, “Signals should generally not be used to trigger the “default” behavior for an action, but to enable others to trigger additional behavior. If a “default” behavior is intended to be provided by another object, then a callback should be provided by that object.”

I’ve read that several times, and I just can’t understand what is being expressed there. Can someone give an example of what not to do with Signals? It isn’t clear to me what is meant by a “default behavior”.

Thank you.

1 Like

I think what it is saying is that the thing sending a signal should not be expecting anyone to listen to it or act on it: it’s a fire and forget kind of thing. If the originator is expecting an action to happen based on the signal, then it should have a registered callback that it can explicitly call, rather than firing a signal and hoping something is registered to act on the signal. I think it’s a question of who is responsible for what.

An example of where this makes a difference is if the originator expects some action to be done: if the originator is explicitly calling a registered callback, it can handle errors, or take action if a callback is not registered, and make sure that only one default action happens. However, if it uses a signal, it has no idea if anyone picked up the signal and did something with it, and it doesn’t know if multiple things did a “default” action based on the signal.

2 Likes