diff --git a/src/ReplicatedStorage/FastSignal/.gitignore b/src/ReplicatedStorage/FastSignal/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/src/ReplicatedStorage/FastSignal/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/src/ReplicatedStorage/FastSignal/index.d.ts b/src/ReplicatedStorage/FastSignal/index.d.ts new file mode 100644 index 0000000..4c92653 --- /dev/null +++ b/src/ReplicatedStorage/FastSignal/index.d.ts @@ -0,0 +1,150 @@ +/** + * A class which holds data and methods for ScriptConnections. + */ +export interface ScriptConnection { + /** + * A boolean which determines if a ScriptConnection is active or not. + * @readonly + */ + readonly Connected: boolean; + + /** + * Disconnects a connection, any `.Fire` calls from now on will not + * invoke this connection's handler. + * + * ```ts + * const connection = ScriptSignal.Connect(() => {}) + * + * connection.Connected -> true + * connection.Disconnect() + * connection.Connected -> false + * ``` + */ + Disconnect(): void; +} + +interface ScriptSignal { + readonly ClassName: "ScriptSignal"; + + /* + * Creates a ScriptSignal object. + */ + new (): ScriptSignal; + + /** + * Returns a boolean determining if the object is a ScriptSignal. + * + * ```ts + * const janitor = new Janitor() + * const signal = new ScriptSignal() + * + * ScriptSignal.Is(signal) -> true + * ScriptSignal.Is(janitor) -> false + * ``` + */ + Is(object: any | object): boolean; + + /** + * Returns a boolean which determines if a ScriptSignal object is active. + * + * ```ts + * ScriptSignal.IsActive() -> true + * ScriptSignal.Destroy() + * ScriptSignal.IsActive() -> false + * ``` + */ + IsActive(): boolean; + + /** + * Connects a handler to a ScriptSignal object. + * + * ```ts + * ScriptSignal.Connect((text) => { + * print(text) + * }) + * + * ScriptSignal.Fire("Something") + * ScriptSignal.Fire("Something else") + * + * // Output: "Something" and then "Something else" are printed + * ``` + */ + Connect(heandler: (...any: T) => void): ScriptConnection; + + /** + * Connects a handler to a ScriptSignal object, but only allows that + * conneciton to run once. Any `.Fire` calls called afterwards won't trigger anything. + * + * ```ts + * ScriptSignal.Once(() => { + * print("Conneciton fired") + * }) + * + * ScriptSignal.Fire() + * ScriptSignal.Fire() + * + * // Output: "Connection fired" is only fired once + * ``` + */ + Once(handler: (...any: T) => void): ScriptConnection; + + /** + * Yields the thread until a `.Fire` call occurs, returns what the signal was fired with. + * + * ```ts + * task.spawn(() => { + * print(ScriptSignal.Wait()) + * }) + * + * ScriptSignal.Fire("Arg", undefined, 1, 2, 3, undefined) + * + * // Output: "Arg", nil, 1, 2, 3, nil are printed + * ``` + */ + Wait(): LuaTuple; + + /** + * Fires a ScriptSignal object with the arguments passed. + * + * ```ts + * ScriptSignal.Connect((text) => { + * print(text) + * }) + * + * ScriptSignal.Fire("Some Text...") + * ScriptSignal.Fire("Some Text...") + * + * // Output: "Some Text..." is printed twice + */ + Fire(...any: T): void; + + /** + * Disconnects all connections from a ScriptSignal object without making it unusable. + * + * ```ts + * const connection = ScriptSignal.Connect(() => {}) + * + * conneciton.Connected -> true + * ScriptSignal.DisconnectAll() + * conneciton.Connected -> false + * ``` + */ + DisconnectAll(): void; + + /** + * Destroys a ScriptSignal object, disconnecting all connections and making it unusable. + * + * ```ts + * ScriptSignal.Destroy() + * + * const connection = ScriptSignal.Connect(() = {}) + * connection.Connected -> false + * ``` + */ + Destroy(): void; +} + +/** + * A class which holds data and methods for ScriptSignals. + */ +export declare const FastSignal: ScriptSignal; diff --git a/src/ReplicatedStorage/FastSignal/package-lock.json b/src/ReplicatedStorage/FastSignal/package-lock.json new file mode 100644 index 0000000..695a59b --- /dev/null +++ b/src/ReplicatedStorage/FastSignal/package-lock.json @@ -0,0 +1,23 @@ +{ + "name": "@rbxts/fastsignal", + "version": "10.4.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@rbxts/fastsignal", + "version": "10.4.0", + "license": "MIT", + "devDependencies": { + "@rbxts/compiler-types": "^3.0.0-types.0" + } + }, + "node_modules/@rbxts/compiler-types": { + "version": "3.0.0-types.0", + "resolved": "https://registry.npmjs.org/@rbxts/compiler-types/-/compiler-types-3.0.0-types.0.tgz", + "integrity": "sha512-VGOHJPoL7+56NTatMGqQj3K7xWuzEV+aP4QD5vZiHu+bcff3kiTmtoadaF6NkJrmwfFAvbsd4Dg764ZjWNceag==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/src/ReplicatedStorage/FastSignal/package.json b/src/ReplicatedStorage/FastSignal/package.json new file mode 100644 index 0000000..9db2109 --- /dev/null +++ b/src/ReplicatedStorage/FastSignal/package.json @@ -0,0 +1,30 @@ +{ + "name": "@rbxts/fastsignal", + "version": "10.4.0", + "description": "Lua Signal library, aims at being similar and familiar to RBXScriptSignals.", + "keywords": [ + "roblox", + "luau" + ], + "homepage": "https://rblxutils.github.io/FastSignal/", + "bugs": { + "url": "https://github.com/RBLXUtils/FastSignal/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/RBLXUtils/FastSignal.git" + }, + "license": "MIT", + "author": "LucasMZReal", + "main": "init.lua", + "types": "index.d.ts", + "files": [ + "init.lua", + "index.d.ts", + "Deferred.lua", + "Immediate.lua" + ], + "devDependencies": { + "@rbxts/compiler-types": "^3.0.0-types.0" + } +}