From 1bec18ccfc6e96f263bb345f81365fd6c4415c83 Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Mon, 12 Apr 2021 18:49:30 -0400 Subject: [PATCH 1/3] Fix bug for Streamable to properly handle instances that are immediately available --- src/Knit/Util/Streamable.lua | 39 ++++++++++++++++++++++---------- src/Knit/Util/StreamableUtil.lua | 10 ++++---- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/Knit/Util/Streamable.lua b/src/Knit/Util/Streamable.lua index 196b6184..09db64d0 100644 --- a/src/Knit/Util/Streamable.lua +++ b/src/Knit/Util/Streamable.lua @@ -5,7 +5,7 @@ --[[ streamable = Streamable.new(parent: Instance, childName: string) - + streamable:Observe(handler: (child: Instance, maid: Maid) -> void): Connection streamable:Destroy() @@ -22,27 +22,42 @@ Streamable.__index = Streamable function Streamable.new(parent, childName) + local self = setmetatable({}, Streamable) + self._maid = Maid.new() self._shown = Signal.new(self._maid) self._shownMaid = Maid.new() self._maid:GiveTask(self._shownMaid) + self.Instance = parent:FindFirstChild(childName) - self._maid:GiveTask(parent.ChildAdded:Connect(function(child) + + local function OnInstanceSet() + self._shown:Fire(self.Instance, self._shownMaid) + self._shownMaid:GiveTask(self.Instance:GetPropertyChangedSignal("Parent"):Connect(function() + if (not self.Instance.Parent) then + self._shownMaid:DoCleaning() + end + end)) + self._shownMaid:GiveTask(function() + self.Instance = nil + end) + end + + local function OnChildAdded(child) if (child.Name == childName and not self.Instance) then self.Instance = child - self._shown:Fire(child, self._shownMaid) - self._shownMaid:GiveTask(child:GetPropertyChangedSignal("Parent"):Connect(function() - if (not child.Parent) then - self._shownMaid:DoCleaning() - end - end)) - self._shownMaid:GiveTask(function() - self.Instance = nil - end) + OnInstanceSet() end - end)) + end + + self._maid:GiveTask(parent.ChildAdded:Connect(OnChildAdded)) + if (self.Instance) then + OnInstanceSet() + end + return self + end diff --git a/src/Knit/Util/StreamableUtil.lua b/src/Knit/Util/StreamableUtil.lua index 5ddf1080..74c5c52d 100644 --- a/src/Knit/Util/StreamableUtil.lua +++ b/src/Knit/Util/StreamableUtil.lua @@ -3,14 +3,14 @@ -- March 03, 2021 --[[ - + StreamableUtil.Compound(observers: {Observer}, handler: ({[child: string]: Instance}, maid: Maid) -> void): Maid - + Example: - + local streamable1 = Streamable.new(someModel, "SomeChild") local streamable2 = Streamable.new(anotherModel, "AnotherChild") - + StreamableUtil.Compound({S1 = streamable1, S2 = streamable2}, function(streamables, maid) local someChild = streamables.S1.Instance local anotherChild = streamables.S2.Instance @@ -18,7 +18,7 @@ -- Cleanup end) end) - + --]] From e03ba8b1c312bbc1a44308c4f6ef5513c0c1abe6 Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Mon, 12 Apr 2021 18:54:34 -0400 Subject: [PATCH 2/3] Isolate instance to scope --- src/Knit/Util/Streamable.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Knit/Util/Streamable.lua b/src/Knit/Util/Streamable.lua index 09db64d0..594dac97 100644 --- a/src/Knit/Util/Streamable.lua +++ b/src/Knit/Util/Streamable.lua @@ -33,14 +33,17 @@ function Streamable.new(parent, childName) self.Instance = parent:FindFirstChild(childName) local function OnInstanceSet() - self._shown:Fire(self.Instance, self._shownMaid) - self._shownMaid:GiveTask(self.Instance:GetPropertyChangedSignal("Parent"):Connect(function() - if (not self.Instance.Parent) then + local instance = self.Instance + self._shown:Fire(instance, self._shownMaid) + self._shownMaid:GiveTask(instance:GetPropertyChangedSignal("Parent"):Connect(function() + if (not instance.Parent) then self._shownMaid:DoCleaning() end end)) self._shownMaid:GiveTask(function() - self.Instance = nil + if (self.Instance == instance) then + self.Instance = nil + end end) end From ea18f5fc992e77a2fa74c08d7871d7c09a463370 Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Mon, 12 Apr 2021 18:59:16 -0400 Subject: [PATCH 3/3] Bump version --- src/Knit/Version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Knit/Version.txt b/src/Knit/Version.txt index c61406f6..37881323 100644 --- a/src/Knit/Version.txt +++ b/src/Knit/Version.txt @@ -1 +1 @@ -0.0.14-alpha \ No newline at end of file +0.0.15-alpha \ No newline at end of file