Skip to content

Commit

Permalink
Refactor function names and improve error handling
Browse files Browse the repository at this point in the history
Simplified the names of several functions in the UnitFrames module, removing redundant 'Element' prefixes. Also replaced underscore placeholders with 'nil' for clarity in UF.Elements:Register calls across multiple files. Added a type check to ensure that an update function is valid before attempting to call it, improving error handling.
  • Loading branch information
Wutname1 committed Aug 21, 2024
1 parent bbc213f commit 015fe95
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Modules/UnitFrames/Elements/ClassIcon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local L = SUI.L

---@param frame table
---@param DB table
local function ElementBuild(frame, DB)
local function Build(frame, DB)
frame.ClassIcon = frame:CreateTexture(nil, 'BORDER')
frame.ClassIcon.Sizeable = true
frame.ClassIcon.shadow = frame:CreateTexture(nil, 'BACKGROUND')
Expand All @@ -24,7 +24,7 @@ end

---@param frame table
---@param settings? table
local function ElementUpdate(frame, settings)
local function Update(frame, settings)
local element = frame.ClassIcon
local DB = settings or element.DB
local reaction = UnitReaction(frame.unit, 'player')
Expand All @@ -50,7 +50,7 @@ end

---@param unitName string
---@param OptionSet AceConfig.OptionsTable
local function ElementOptions(unitName, OptionSet)
local function Options(unitName, OptionSet)
local ElementSettings = UF.CurrentSettings[unitName].elements.ClassIcon
local function OptUpdate(option, val)
UF.CurrentSettings[unitName].elements.ClassIcon[option] = val
Expand Down Expand Up @@ -106,7 +106,7 @@ local Settings = {
},
}

UF.Elements:Register('ClassIcon', ElementBuild, ElementUpdate, ElementOptions, Settings)
UF.Elements:Register('ClassIcon', Build, Update, Options, Settings)

do -- ClassIcon as an SUIUF module
local function Update(self, event, unit)
Expand Down
2 changes: 1 addition & 1 deletion Modules/UnitFrames/Elements/PVPSpecIcon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ local Settings = {
},
}

UF.Elements:Register('PVPSpecIcon', Build, _, _, Settings)
UF.Elements:Register('PVPSpecIcon', Build, nil, nil, Settings)
2 changes: 1 addition & 1 deletion Modules/UnitFrames/Elements/RaidRoleIndicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ local Settings = {
},
}

UF.Elements:Register('RaidRoleIndicator', Build, _, _, Settings)
UF.Elements:Register('RaidRoleIndicator', Build, nil, nil, Settings)
2 changes: 1 addition & 1 deletion Modules/UnitFrames/Elements/RaidTargetIndicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ local Settings = {
},
}

UF.Elements:Register('RaidTargetIndicator', Build, _, _, Settings)
UF.Elements:Register('RaidTargetIndicator', Build, nil, nil, Settings)
2 changes: 1 addition & 1 deletion Modules/UnitFrames/Elements/SummonIndicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ local Settings = {
},
}

UF.Elements:Register('SummonIndicator', Build, _, _, Settings)
UF.Elements:Register('SummonIndicator', Build, nil, nil, Settings)
2 changes: 1 addition & 1 deletion Modules/UnitFrames/Elements/TargetIndicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ local Settings = {
},
}

UF.Elements:Register('TargetIndicator', Build, Update, _, Settings)
UF.Elements:Register('TargetIndicator', Build, Update, nil, Settings)
5 changes: 5 additions & 0 deletions Modules/UnitFrames/Handlers/Elements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ end
---@return boolean --False if the element did not provide an updater
function Elements:Update(frame, ElementName, DB)
if UF.Elements.List[ElementName] and UF.Elements.List[ElementName].Update then
if type(UF.Elements.List[ElementName].Update) ~= 'function' then
SUI:Error('Element ' .. ElementName .. ' does not have a valid update function.', 'UnitFrames')
return false
end

UF.Elements.List[ElementName].Update(frame, DB or UF.CurrentSettings[frame.unitOnCreate].elements[ElementName] or {})
return true
else
Expand Down

0 comments on commit 015fe95

Please sign in to comment.