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

Add a communication channel between Lua components #299

Open
vktr opened this issue Jan 20, 2024 · 1 comment
Open

Add a communication channel between Lua components #299

vktr opened this issue Jan 20, 2024 · 1 comment

Comments

@vktr
Copy link
Contributor

vktr commented Jan 20, 2024

Let's say we have a plugin for Discord notifications - it knows how to interact with the Discord API and push messages to a channel. Then we have another plugin that monitors free disk space. The author of this plugin wants the user to be able to get notifications when the disk space runs low.

With a simple message bus thingy we can decouple this, and let plugins interact without being directly aware of eachother.

The Discord plugin would look something like this,

local bus = require "bus"

function porla.init()
    bus.on("user.notify", function (args)
        sendDiscordNotification(args.message)
    end)
end

It would basically listen on a pre-defined "channel" and then provide a callback that is invoked.

This allows other plugins, like the theoretical disk space monitor, to do something like this,

local bus = require "bus"

function warnSpaceLow()
    bus.publish("user.notify", { message = "Disk space is running low!" })
end

Porla needs to decide on some pre-defined channels for user notifications etc, but nothing stops plugins from listening on their own channels to do plugin-specific things.

Getting this in place makes it easier for plugin authors to focus on what their own plugin should do, for example the Discord plugin can focus on Discord notifications. It also let's the user switch out the Discord plugin for other types of plugins that also handle the user.notify channel if they want their notifications elsewhere.

@bonny1992
Copy link

This is really good.
Very useful to intertwine the plugins without rewriting the logic in every one!

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

No branches or pull requests

2 participants