Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
Improve memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
boatbomber authored and clockworksquirrel committed Sep 3, 2020
1 parent ef9026a commit 8b44c32
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ function State.new(InitialState)
--]]
self.ProtectType = false

--[[
Handle firing bindables created from State:GetChangedSignal
Added by @boatbomber in v0.2.0
--]]
self.Changed:Connect(function(OldState, ChangedKey)
local Signal = self.__bindables[ChangedKey]

if Signal then
Signal:Fire(self:Get(ChangedKey), OldState[ChangedKey], OldState)
end
end)

--[[
Return the new completed BasicState instance
--]]
Expand Down Expand Up @@ -223,15 +236,15 @@ end
RBXScriptConnection
--]]
function State:GetChangedSignal(Key)
local Signal = Instance.new("BindableEvent")
local Signal = self.__bindables[Key]

self.Changed:Connect(function(OldState, ChangedKey)
if (Key == ChangedKey) then
Signal:Fire(self:Get(Key), OldState[Key], OldState)
end
end)
if Signal then
return Signal.Event
end

Signal = Instance.new("BindableEvent")
self.__bindables[Key] = Signal

self.__bindables[#self.__bindables + 1] = Signal
return Signal.Event
end

Expand Down

0 comments on commit 8b44c32

Please sign in to comment.