Skip to content

A fork of LemonSignal with additional features added

License

Notifications You must be signed in to change notification settings

CavefulGames/LimeSignal

Repository files navigation

한국어 👈

English

LimeSignal

Pesde

This is a fork of LemonSignal with some extra features added and some unnecessary parts removed.

Changes in v0.2.0

  • Added ImmutableEvent (its connections are intended to be immutable from outside)
  • Renamed connectOnce to once.
  • Bindable.event is now ImmutableEvent.
  • Sligtly, a little bit more micro optimized.
  • Added better error messages.
  • Added english version of README.

Features

  • In theory, performance and speed are not as good as LemonSignal.
  • You can use the package caveful_games/threadpool to keep threads in a single shared threadpool space.
  • Added several useful classes from LemonSignal.
  • All class methods and properties are in camelCase. Note that the methods in the original RBXScriptSignal and Signal modules were in PascalCase.
  • Pure luau support has been removed (LimeSignal is Roblox only).

Installation (via pesde)

  • NOTE: This package is no longer updated for wally.
pesde add caveful_games/limesignal

Example Usage

Signal

local sig = limesignal.Signal.new()

sig:connect(function()
	-- do something
end)

sig:fire()

Bindable

-- API inspired by roblox's BindableEvent instance

local bindable = limesignal.Bindable.new()

bindable.event:connect(function()
	-- do something
end)

bindable:fire()

Event & Emitter

-- Useful when you want to make event's `fire` method into private!

local Class = {}

local emit = limesignal.createEmitter()

function Class.new()
	return setmetatable({
		onSomething = limesignal.Event.from(emit) :: limesignal.Event<number, string>
	}, Class)
end

function Class.something(self)
	emit(self.onSomething, 123, "hi") -- ofc typed!
end

local object = Class.new()

object.onSomething:connect(function(a, b) -- typed!
	print(a, b) -- 123, "hi"
end)

object:something()

object.onSomething:fire() -- no you can't

ImmutableEvent & Emitter + Destroyer

-- Useful when you want to make event's `fire` method into private! but intended to be immutable connections from outside.
-- DisconnectAll(=destroy) internally using destroyer!

local Class = {}

local destroy = limesignal.createDestroyer()
local emit = limesignal.createEmitter()

function Class.new()
	return setmetatable({
		onSomething = limesignal.ImmutableEvent.from(emit, destroy) :: limesignal.ImmutableEvent<number, string>
	}, Class)
end

function Class.something(self)
	destroy(self.onSomething) -- disconnects all connections from ImmutableEvent
end

local object = Class.new()

object.onSomething:once(function(a, b) -- typed!
	print(a, b) -- 123, "hi"
end)

object.onSomething:fire() -- no you can't
object.onSomething:disconnectAll() -- no you can't

object:something()

About

A fork of LemonSignal with additional features added

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages