Signals are a powerful tool in Roblox development for managing custom events and communication between different parts of your game. They allow scripts to trigger specific actions without tightly coupling components, making your code more modular and easier to maintain.
This Signal Module introduces four flexible signal types designed to fit various needs:
BindableSignal: Ideal for reacting to property changes with a binding function.
ReadableSignal: Extends BindableSignal by allowing data retrieval when the signal is fired.
Signal: A standard signal with basic event handling and firing capabilities.
SimpleSignal: A lightweight signal with essential features, including destruction support.
Example use
Detailed API Reference
BindableSignal
Returns:BindableSignal, Bind (Trigger the signal.), Destroy (Destroy the signal and disconnect all connections.), DisconnectAll (Disconnects all active connections from the signal.)
API:
Connect: Connect a function.
Once: Connect a function that runs only once.
HasConnections: Check for active connections.
Wait: Wait for signal to be fired.
ReadableSignal
Returns:ReadableSignal, Bind (Trigger the signal.), Destroy (Destroy the signal and disconnect all connections.), DisconnectAll (Disconnects all active connections from the signal.)
API:
Connect: Connect a function.
Once: Connect a function that runs only once.
HasConnections: Check for active connections.
Wait: Wait for signal to be fired.
Get: Retrieve the data passed when fired.
Signal
Returns:Signal, Destroy (Destroy the signal and disconnect all connections.), DisconnectAll (Disconnects all active connections from the signal.)
API:
Connect: Connect a function.
Once: Connect a function that runs only once.
HasConnections: Check for active connections.
Wait: Wait for signal to be fired.
Fire: Trigger the signal.
SimpleSignal
Return:Signal
API:
Connect: Connect a function.
Once: Connect a function that runs only once.
HasConnections: Check for active connections.
Wait: Wait for signal to be fired.
DisconnectAll: Disconnects all active connections from the signal.
Fire: Trigger the signal.
Destroy: Destroy the signal and disconnect all connections.
I also have another version that is based on Sleitnick’s Signal implementation. Would you be interested in seeing it? I plan to share it later, so I can provide it now if you’d like to take a look.
– i understand now what you meaning im making new module wait for it
But hold on, I think my Signal can achieve that as well. You can try using this approach:
local TestSignal = Signal.createBindableSignal(function(property: string) end, '')
export type Some = {
TestSignal = typeof(TestSignal)
}
This method maintains type safety and works similarly to Sleitnick’s signal system, but with stronger typing. It may be a little more complex than Sleitnick’s approach
Apologies if I misunderstood what you were referring to.
Anyway, I will release another version later that is based on the RbxUtil Signal.
Do you think making Signal.Connect() work without : and calling it directly like Signal.Connect() is a good idea? Or would it be better to stick with :?
because i found problem if i still use : to make auto field
I would stick to using : if you didn’t, that would mean storing references to the actual reference somewhere else. I think that’d also be slower because metatable are optimized for things like OOP.
You’d should try rebuilding your module but without requiring and empty anonymous function for the typing (I assume that’s what it’s for)