local function f(f,e,t)local I={}for f,e in pairs(f)do I[f]=e end I[e]=t return I end local function e(f,e)local t={}for f,I in pairs(f)do if f~=e then t[f]=I end end return t end local function t()local t={}local function I(I,S)assert(typeof(S)=="\102\117\110\099\116\105\111\110","\067\097\110 \111\110\108\121 \115\117\098\115\099\114\105\098\101 \116\111 \115\105\103\110\097\108\115 \119\105\116\104 \097 \102\117\110\099\116\105\111\110\046")local b={callback=S}t=f(t,S,b)local function a()assert(not b.disconnected,"\076\105\115\116\101\110\101\114\115 \099\097\110 \111\110\108\121 \098\101 \100\105\115\099\111\110\110\101\099\116\101\100 \111\110\099\101\046")b.disconnected=true t=e(t,S)end return a end local function S(f,...)for f,e in pairs(t)do if not e.disconnected then f(...)end end end return{subscribe=I;fire=S}end return t
local function addToMap(map, addKey, addValue)
	local new = {}

	for key, value in pairs(map) do
		new[key] = value
	end

	new[addKey] = addValue

	return new
end

local function removeFromMap(map, removeKey)
	local new = {}

	for key, value in pairs(map) do
		if key ~= removeKey then
			new[key] = value
		end
	end

	return new
end

local function createSignal()
	local connections = {}

	local function subscribe(self, callback)
		assert(typeof(callback) == "function", "Can only subscribe to signals with a function.")

		local connection = {
			callback = callback,
		}

		connections = addToMap(connections, callback, connection)

		local function disconnect()
			assert(not connection.disconnected, "Listeners can only be disconnected once.")

			connection.disconnected = true
			connections = removeFromMap(connections, callback)
		end

		return disconnect
	end

	local function fire(self, ...)
		for callback, connection in pairs(connections) do
			if not connection.disconnected then
				callback(...)
			end
		end
	end

	return {
		subscribe = subscribe,
		fire = fire,
	}
end

return createSignal