Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/observablecollection/src/Shared/ObservableMap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ end

function ObservableMap:_observeKeyValueChanged(packValue)
return Observable.new(function(sub)
local maid = Maid.new()
local brios = {}

local function handleValue(key, value)
if value ~= nil then
local brio = packValue(key, value)
maid[key] = brio
if brios[key] then
brios[key]:Destroy()
end
brios[key] = brio
sub:Fire(brio)
else
maid[key] = nil
if brios[key] then
brios[key]:Destroy()
brios[key] = nil
end
end
end

Expand All @@ -128,7 +134,9 @@ function ObservableMap:_observeKeyValueChanged(packValue)
self._maid[sub] = nil
conn:Disconnect()
sub:Complete()
maid:Destroy()
for _, v in brios do
v:Destroy()
end
end
self._maid[sub] = cleanup
return cleanup
Expand Down
16 changes: 14 additions & 2 deletions src/observablecollection/src/Shared/ObservableSet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ function ObservableSet:ObserveItemsBrio()
end

local maid = Maid.new()
local brios = {}

local function handleItem(item)
local brio = Brio.new(item)
maid[item] = brio
if brios[item] then
brios[item]:Destroy()
end
brios[item] = brio
sub:Fire(brio)
end

Expand All @@ -89,13 +93,21 @@ function ObservableSet:ObserveItemsBrio()

maid:GiveTask(self.ItemAdded:Connect(handleItem))
maid:GiveTask(self.ItemRemoved:Connect(function(item)
maid[item] = nil
-- Checking the brio exists first may be superflous?
-- I worry about strange ordering as a result of signals.
if brios[item] then
brios[item]:Destroy()
brios[item] = nil
end
end))

self._maid[sub] = maid
maid:GiveTask(function()
self._maid[sub] = nil
sub:Complete()
for _, v in brios do
v:Destroy()
end
end)

return maid
Expand Down