Skip to content

Commit

Permalink
Handle story cleanup properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ImAvafe committed Sep 4, 2024
1 parent fa50bc1 commit b117d16
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 59 deletions.
11 changes: 8 additions & 3 deletions src/Components/Avatar.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ return {
end
end)

local Instance = Scope:Frame {
Scope:innerScope({
function()
task.cancel(RandomizerThread)
end,
})

Scope:Frame {
Parent = Parent,
Padding = Scope:Computed(function(use)
return UDim.new(0, use(Theme.StrokeThickness["4"]))
Expand Down Expand Up @@ -97,8 +103,7 @@ return {
}

return function()
Instance:Destroy()
task.cancel(RandomizerThread)
Scope:doCleanup()
end
end,
}
13 changes: 9 additions & 4 deletions src/Components/Badge.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ return {

local NotificationCount = Scope:Value(0)

local CountLoop = task.spawn(function()
local CountThread = task.spawn(function()
while task.wait(0.08) do
if peek(NotificationCount) == 100 then
task.wait(3)
Expand All @@ -35,7 +35,13 @@ return {
end
end)

local Instance = Scope:Frame {
Scope:innerScope({
function()
task.cancel(CountThread)
end,
})

Scope:Frame {
Parent = Parent,
ListEnabled = true,
ListPadding = Scope:Computed(function(use)
Expand Down Expand Up @@ -90,8 +96,7 @@ return {
}

return function()
Instance:Destroy()
coroutine.close(CountLoop)
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/Base.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ return {
local Theme: Themer.ThemeObject = Themer.Theme:now()
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)

local Instance = Scope:Base {
Scope:Base {
Parent = Parent,
ListEnabled = true,
Padding = Scope:Computed(function(use)
Expand Down Expand Up @@ -108,7 +108,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/Button.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
ListEnabled = true,
ListPadding = Scope:Computed(function(use)
Expand Down Expand Up @@ -71,7 +71,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/Card.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
Size = UDim2.fromOffset(300, 0),
AutomaticSize = Enum.AutomaticSize.Y,
Expand Down Expand Up @@ -63,7 +63,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
2 changes: 1 addition & 1 deletion src/Components/Checkbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ return function(Scope: Fusion.Scope<any>, Props: Props)
end
end)

return BaseButton(Util.CombineProps(Props, {
return Scope:BaseButton(Util.CombineProps(Props, {
Name = "Checkbox",
BackgroundColor3 = EffectiveColor,
BackgroundTransparency = Scope:Spring(
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Checkbox.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
Padding = Scope:Computed(function(use)
return UDim.new(0, use(Theme.StrokeThickness["1"]))
Expand Down Expand Up @@ -51,7 +51,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/Divider.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
Size = UDim2.fromOffset(300, 0),
AutomaticSize = Enum.AutomaticSize.Y,
Expand All @@ -44,7 +44,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/Heading.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
ListEnabled = true,
ListPadding = Scope:Computed(function(use)
Expand All @@ -39,7 +39,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/Icon.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ return {
story = function(Parent: GuiObject)
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)

local Instance = Scope:Icon {
Scope:Icon {
Parent = Parent,
Image = "rbxassetid://11560341132",
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/IconButton.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
Padding = Scope:Computed(function(use)
return UDim.new(0, use(Theme.StrokeThickness["1"]))
Expand Down Expand Up @@ -65,7 +65,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/IconText.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ return {
story = function(Parent: GuiObject)
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)

local Instance = Scope:IconText {
Scope:IconText {
Parent = Parent,
Content = {
"Here's a shop icon: ",
Expand All @@ -25,7 +25,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/Image.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
AutomaticSize = Enum.AutomaticSize.XY,
ListEnabled = true,
Expand All @@ -39,7 +39,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/MenuFrame.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
Padding = Scope:Computed(function(use)
return UDim.new(0, use(Theme.StrokeThickness["1"]))
Expand All @@ -44,7 +44,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
15 changes: 10 additions & 5 deletions src/Components/NumberSpinner.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ return {
end
end)

local Instance = Scope:Frame {
Scope:innerScope({
function()
task.cancel(RandomizerThread)
task.cancel(RandomizerDecimalThread)
task.cancel(CountThread)
end,
})

Scope:Frame {
Parent = Parent,
Size = UDim2.fromOffset(300, 0),
AutomaticSize = Enum.AutomaticSize.Y,
Expand All @@ -62,10 +70,7 @@ return {
}

return function()
task.cancel(RandomizerThread)
task.cancel(RandomizerDecimalThread)
task.cancel(CountThread)
Instance:Destroy()
Scope:doCleanup()
end
end,
}
24 changes: 15 additions & 9 deletions src/Components/ProgressBar.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ return {
local Progress = Scope:Value(0)
local Color = Scope:Value(Color3.fromRGB(255, 0, 0))

local Instance = Scope:Frame {
local ColorThread = task.spawn(function()
while task.wait(1) do
Progress:set(math.random(0, 1000) / 1000)
Color:set(ColorUtils.Rotate(peek(Color), 100))
end
end)

Scope:innerScope({
function()
task.cancel(ColorThread)
end,
})

Scope:Frame {
Parent = Parent,
ListEnabled = true,
ListHorizontalFlex = Enum.UIFlexAlignment.Fill,
Expand Down Expand Up @@ -186,15 +199,8 @@ return {
},
}

task.spawn(function()
while task.wait(1) do
Progress:set(math.random(0, 1000) / 1000)
Color:set(ColorUtils.Rotate(peek(Color), 100))
end
end)

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/ScrollingFrame.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ return {
story = function(Parent: GuiObject)
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)

local Instance = Scope:ScrollingFrame {
Scope:ScrollingFrame {
Parent = Parent,
Size = UDim2.fromOffset(200, 200),
CanvasSize = UDim2.new(UDim.new(1, 0), UDim.new(0, 1000)),
AutomaticCanvasSize = Enum.AutomaticSize.None,
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
4 changes: 2 additions & 2 deletions src/Components/SwitchInput.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ return {
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Components)> = Scoped(Fusion, Components)
local Theme: Themer.ThemeObject = Themer.Theme:now()

local Instance = Scope:Frame {
Scope:Frame {
Parent = Parent,
Padding = Scope:Computed(function(use)
return UDim.new(0, use(Theme.StrokeThickness["1"]))
Expand All @@ -37,7 +37,7 @@ return {
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
}
3 changes: 1 addition & 2 deletions src/Components/Text.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ return {
story = function(Parent: GuiObject)
local Scope: Fusion.Scope<typeof(Fusion) & typeof(Util) & typeof(Components)> = Scoped(Fusion, Util, Components)

local Instance = Scope:Text {
Scope:Text {
Parent = Parent,
Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
}

return function()
Instance:Destroy()
Scope:doCleanup()
end
end,
Expand Down
Loading

0 comments on commit b117d16

Please sign in to comment.