Skip to content

Commit

Permalink
add clean key
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesrje committed Nov 9, 2024
1 parent 9af227f commit 4d70c2f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/Instances/New.luau
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local Default = require(Root.Instances.Default)
-- Module

--[=[
Creates a new instance or component with the provided children and props.
Creates a new instance or component with the provided children and properties.
[Learn More](https://luminlabsdev.github.io/ui-framework/api/#new)
]=]
Expand All @@ -25,11 +25,11 @@ return function<T>(
local Success, Result = pcall(Instance.new, component) -- Create the instance wrapped inside pcall

if Success then
if Default[component] then
for prop, value in Default[component] do
(Result :: any)[prop] = value
end
end
if Default[component] then
for prop, value in Default[component] do
(Result :: any)[prop] = value
end
end

if properties then
for property, value in properties :: any do
Expand Down
2 changes: 1 addition & 1 deletion src/Instances/Update.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local Types = require(script.Parent.Parent.Types)
-- Module

--[=[
Updates an instance, adding properties or children.
Updates an instance, writing to its properties or adding children.
[Learn More](https://luminlabsdev.github.io/ui-framework/api/#update)
]=]
Expand Down
25 changes: 25 additions & 0 deletions src/Keys/Clean.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Variables
local Packages = script.Parent.Parent.Parent.Parent.Packages
local Utility = script.Parent.Utility
local Keys = require(Utility.Keys)
local Debugger = require(Packages.debugger)


-- Module

--[=[
Cleans and removes the items provided to they key when the parent instance is destroyed.
[Learn More](https://luminlabsdev.github.io/ui-framework/api/keys/#clean)
]=]
return function()
if not Keys["Clean"] then
Keys["Clean"] = function(instance: Instance, values: {any})
Debugger.Assert(type(values) == "table", "InvalidType", "table", type(values))
instance.Destroying:Once(function()

end)
end
end
return Keys["Clean"]
end
5 changes: 3 additions & 2 deletions src/Utility/Utils.luau
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ end
local function ApplyConstructorProperty(instance: Instance, prop: string, value: Types.Constructor)
local Property = (instance :: any)[prop]

property(instance, value)
-- Call the _bind method of the Service.
CheckTypeAndCall(Property, value:Get(), function()
(value :: Types.Constructor):_bind(prop, instance)
Expand All @@ -54,8 +55,8 @@ end

local function ApplyProperty(instance: Instance, property: any, value: any)
-- If the property is an Aegis key then
if Is.Key(property) then
(property :: Types.Key).ApplyKey(instance, value)
if type(property) == "function" then
property(instance, value)
elseif type(property) == "string" then
-- but if the property is a string then
if Is.AegisConstructor(value) then
Expand Down
17 changes: 6 additions & 11 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ local Keys = script.Keys

local Types = require(script.Types)
local Debugger = require(Packages.debugger)
local RegisterKey = require(Keys.RegisterKey)

for _, key in script.Keys:GetChildren() do
RegisterKey(require(key) :: Types.Key)
end

-- Types
export type Key = Types.Key
Expand All @@ -32,15 +27,15 @@ Debugger.SetMetadata({
return table.freeze({
New = require(Instances.New),
Update = require(Instances.Update),

Value = require(State.Value),
Compute = require(State.Compute),

Spring = require(Animation.Spring),
Tween = require(Animation.Tween),

OnEvent = require(Keys.List.OnEvent),
OnChange = require(Keys.List.OnChange),

Key = require(Keys.Key),
UnregisterKey = require(Keys.UnregisterKey),
RegisterKey = RegisterKey,
Event = require(Keys.Event),
Change = require(Keys.Change),
Tag = require(Keys.Tag),
Clean = require(Keys.Clean),
})

0 comments on commit 4d70c2f

Please sign in to comment.