A library to prevent UI freezes and kicks when reacting to a large number of quick operations or event spam.
Problem.
Fast input of 10 characters in 1 second will update the list 10 times so ui will be freezing if we have large amount of list elements.
Code:
control:GetNamedChild("InputBox"):SetText(self.searchPhrase)
control:GetNamedChild("InputBox"):SetHandler("OnTextChanged", function(control)
ZO_EditDefaultText_OnTextChanged(control)
self.searchPhrase = control:GetText()
self.list:RefreshData()
end)
Rewrite with addon:
Code:
local searchHandler = LibDelayedHandler:New(function()
self.list:RefreshData()
end, 500)
control:GetNamedChild("InputBox"):SetText(self.searchPhrase)
control:GetNamedChild("InputBox"):SetHandler("OnTextChanged", function(control)
ZO_EditDefaultText_OnTextChanged(control)
self.searchPhrase = control:GetText()
searchHandler:trigger()
end)
The list will be refreshed 500 miliseconds after the last character input.
Another example:
Code:
local scanHandler = LibDelayedHandler:New(function()
self:groupScan()
end, 50)
local function delayedRescan()
scanHandler:trigger()
end
EVENT_MANAGER:RegisterForEvent("MyAddonGroupScan", EVENT_GROUP_UPDATE, delayedRescan)