Skip to content

Commit

Permalink
feat: adds improved cleanup
Browse files Browse the repository at this point in the history
Adds improved cleanup by tidying up the cleanup function and it making it more verbose in the output
  • Loading branch information
jmesrje committed Dec 26, 2024
1 parent 0e14106 commit a4e6723
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
12 changes: 12 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Offers improved cleanup

## [0.3.0-rc3] - 2024-12-24

### Fixed

- Fixes not being able to create multiple actions of the same type under an object

### Removed

- Removes action caching as it has no practical use

## [0.3.0-rc2] - 2024-12-15

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pesde.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "lumin/ui"
version = "0.3.0-rc3"
version = "0.3.0-rc4"
description = "A light, fast, and efficient UI framework that has a small learning curve"
authors = ["2jammers"]
repository = "https://github.com/lumin-org/ui"
Expand Down
2 changes: 1 addition & 1 deletion src/Apply.luau
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ return function(instance: Instance, property: any, value: any)
if PropType == "number" then -- If the property is a modifier
if ValueType == "function" then -- If the value is an action
(value :: Types.Action)(instance)
elseif ValueType == "userdata" then -- If the value is anything else, it's an instance
elseif ValueType == "userdata" then -- If the value is an instance
value.Parent = instance
value.Name = property
end
Expand Down
3 changes: 2 additions & 1 deletion src/Change.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ local Debugger = require(Root.Parent.roblox_packages.debugger)
-- Module

--[=[
Connects a callback to a certain property change event, and supplies the changed prop as an arg.
Allows you to observe changes of properties within an object, and supplies the value of
the changed property as a callback argument.
[Open Documentation](https://lumin-org.github.io/ui/api/actions/#change)
]=]
Expand Down
18 changes: 13 additions & 5 deletions src/Clean.luau → src/Cleanup.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ local Action = require(Root.Action)
local Types = require(Root.Types)
local Debugger = require(Root.Parent.roblox_packages.debugger)

-- Functions

local function Helper(instance: any)
if instance.Destroy then
instance:Destroy()
elseif instance.Disconnect then
instance:Disconnect()
else
Debugger.Fatal("CleanUpNotAllowed")
end
end

-- Module

--[=[
Expand All @@ -16,11 +28,7 @@ return function(values: { any }): Types.Action
Debugger.Assert(type(values) == "table", "InvalidType", "table", type(values))
instance.Destroying:Once(function()
for _, value in values do
if (type(value) == "table" and value._Bind) or typeof(value) == "Instance" then
value:Destroy()
elseif typeof(value) == "RBXScriptConnection" then
value:Disconnect()
end
Helper(value)
end
end)
end)
Expand Down
1 change: 1 addition & 0 deletions src/Logs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ return {
InvalidType = "Expected type %s; got '%s'",
InvalidClass = "'%s' is not an instance class name",
InvalidPropOrEvent = "'%s' is not a property/event of the %s class",
CleanupNotAllowed = "Cleanup of an object without Disconnect or Destroy is not allowed",
}
2 changes: 1 addition & 1 deletion src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ return table.freeze({
State = require(script.State),
Computed = require(script.Computed),
Spring = require(script.Spring),
Cleanup = require(script.Cleanup),
Action = require(script.Action),
Event = require(script.Event),
Changed = require(script.Change),
Tags = require(script.Tags),
Clean = require(script.Clean),
})

0 comments on commit a4e6723

Please sign in to comment.