Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Signal.publish to include some data #4437

Closed
darrenburns opened this issue Apr 22, 2024 · 1 comment · Fixed by #4438
Closed

Allow Signal.publish to include some data #4437

darrenburns opened this issue Apr 22, 2024 · 1 comment · Fixed by #4438

Comments

@darrenburns
Copy link
Member

Right now, when a Signal is published, there's no data attached to it.

Subscribers are informed that the publish happened, but it's up to them to go off and fetch any associated data.

Often that data is associated with the node that published it, so the subscriber is having to know how to access data from the publisher and is coupled to it. Ideally we'd avoid this coupling as it's one of the main benefits of a pubsub system.

It'd be nice to offer a means for publish to an optional extra piece of data to the subscribers callback.

To retain typing, Signal would become generic.

Example:

# Creation of a signal
config_changed_signal = Signal[Config](self, "config-changed")

# Publishing that signal
config_changed_signal.publish(Config(a=1, b=2))

# A callback to run when the signal is published
def callback(config: Config) -> None:
    """Does something with the Config object"""

# Subscribing and passing in the callback
config_changed_signal.subscribe(self, callback)
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant