To see if I understood everything correct about the performance stuff I'd like to show you an example and ask, how I need to change it (including ideas).
Current code:
Lua Code:
button:SetHandler("OnMouseEnter", function(self)
--tooltipText is a local defined variable, outside of the closure, but inside the same function which sets the handler
tooltipText = outputFilterState(false, settingsVars.settings.splitFilters, p_FilterPanelId, buttonId, mappingVars.settingsFilterStateToText[tostring(getSettingsIsFilterOn(buttonId, p_FilterPanelId))])
if tooltipText ~= "" then
local showToolTip = true
--Don't show a tooltip if the context menu for gear sets is shown at the filter button
if contextMenu.GearSetFilter[locVars.gFilterWhere] ~= nil then
showToolTip = contextMenu.GearSetFilter[locVars.gFilterWhere]:IsHidden()
end
--Don't show a tooltip if the context menu for research, deconstruction & improvement is shown at the filter button
if showToolTip and contextMenu.ResDecImpFilter[locVars.gFilterWhere] ~= nil then
showToolTip = contextMenu.ResDecImpFilter[locVars.gFilterWhere]:IsHidden()
end
if showToolTip and contextMenu.SellGuildIntFilter[locVars.gFilterWhere] ~= nil then
showToolTip = contextMenu.SellGuildIntFilter[locVars.gFilterWhere]:IsHidden()
end
if showToolTip then
ZO_Tooltips_ShowTextTooltip(button, BOTTOM, tooltipText)
end
end
end)
Optimized code:
Lua Code:
button.tooltipText = tooltipText
button:SetHandler("OnMouseEnter", function(self)
button.tooltipText = outputFilterState(false, settingsVars.settings.splitFilters, p_FilterPanelId, buttonId, mappingVars.settingsFilterStateToText[tostring(getSettingsIsFilterOn(buttonId, p_FilterPanelId))])
if self.tooltipText ~= "" then
local showToolTip = true
--Don't show a tooltip if the context menu for gear sets is shown at the filter button
if contextMenu.GearSetFilter[locVars.gFilterWhere] ~= nil then
showToolTip = contextMenu.GearSetFilter[locVars.gFilterWhere]:IsHidden()
end
--Don't show a tooltip if the context menu for research, deconstruction & improvement is shown at the filter button
if showToolTip and contextMenu.ResDecImpFilter[locVars.gFilterWhere] ~= nil then
showToolTip = contextMenu.ResDecImpFilter[locVars.gFilterWhere]:IsHidden()
end
if showToolTip and contextMenu.SellGuildIntFilter[locVars.gFilterWhere] ~= nil then
showToolTip = contextMenu.SellGuildIntFilter[locVars.gFilterWhere]:IsHidden()
end
if showToolTip then
ZO_Tooltips_ShowTextTooltip(self, BOTTOM, self.tooltipText)
end
end
end)
I changed the button variable inside the anonymous SetHandler function to use the "self".
And I changed the local tooltipText variable usage inside the anonymous SetHandler function to use the self.tooltipText variable now, which was passed to the button control outside the closure.
But what about all the other variables used inside the anonymous SetHandler function, like "buttonId" (which is a parameter of the calling function, which is setting the handler), "settingsVars.settings.splitFilters" (which is an addon wide known local variable set as the settings in LAM 2.0 panel get changed), "p_FilterPanelId" (which is a parameter of the calling function too)?
Do I need to pass them to the button control too and use the self.variableName inside the anonymouse function then?