tacheometrystestrepo v1.0.5
SimpleSignals
A Roblox-TS RemoteEvent/RemoteFunction/BindableEvent wrapper which puts and end to the hassle of managing events. You can get straight to connecting and firing without any WaitForChild/Instance.new boilerplate, while your event instances get created automatically in the background.
Usage
Example: working with an event called "z"
SimpleClient.on("z", callbackFunc)
gets called on the client, but z
doesn't exist. SimpleSignals will WaitForChild("z")
on the event folder, and when the event gets created on the server, it connects callbackFunc
to it.
But how do events get created?
Any time you call a z
RemoteEvent related function on the server (on(z
, once(z
, fire(z
), a RemoteEvent with name z
gets created - if such a RemoteEvent doesn't exist. RemoteEvents/RemoteFunctions cannot be created on the client.
The same process follows for RemoteFunctions and BindableEvents, except BindableEvents aren't stored in a Folder, rather they're used in an internal Map.
You can import the module this way on the server:
import { Server as SimpleSignals } from "@rbxts/simplesignals";
and on the client:
import { Client as SimpleSignals } from "@rbxts/simplesignals";
SimpleSignals manages events cleanly, without you having to instantiate or to WaitForChild
:
SimpleClient.on("printX", x => {
print(x);
});
SimpleClient.fire("printX", "X");
You never have to create objects you only use once:
const printX = new Instance("RemoteEvent");
printX.Name = "printX";
printX.Parent = game.GetService("ReplicatedStorage");
printX.OnServerEvent.Connect((_, x) => {
print(x);
});
const printX = game.GetService("ReplicatedStorage").WaitForChild("printX");
printX.FireServer("X");
The following table describes where each event is stored:
Event type | Game location | Folder name | Path | |
---|---|---|---|---|
RemoteEvent | ReplicatedStorage | RemoteEvents | game.ReplicatedStorage.RemoteEvents | |
RemoteFunction | ReplicatedStorage | RemoteFunctions | game.ReplicatedStorage.RemoteFunctions | |
BindableEvent | none* |
*BindableEvents are stored in an internal Map.
Where client/SimpleSignals
is:
import { Client } from "@rbxts/simplesignals";
export = Client;
and the same for server/SimpleSignals
:
import { Server } from "@rbxts/simplesignals";
export = Server;
Of course, you can rename the files so they're shorter. I wrote it like this for the sake of being explicit.
You can then import it from the client/server in this way:
import Simple from "server/SimpleSignals";
import Simple from "client/SimpleSignals";
(or something other than Simple
)
API
- Simple:onBindable(
name
: string,callback
: Function) →RBXScriptConnection
- Simple:onceBindable(
name
: string,callback
: Function) →void
- Simple:fireBindable(
name
: string,...args
) →void
- Simple:setCallback(
name
: string,callback
: Function) →void
- Simple:invoke(
name
: string,...args
) →unknown
(return value of the callback)