Download
(931 b)
Download
Updated: 03/02/21 04:50 AM
Compatibility:
Flames of Ambition (6.3.5)
Markarth (6.2.5)
Updated:03/02/21 04:50 AM
Created:10/13/20 02:48 PM
Monthly downloads:1,935
Total downloads:101,106
Favorites:33
MD5:
LibDelayedHandler  Popular! (More than 5000 hits)
Version: 0.0.2
by: zelenin [More]
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)
0.0.2:
- API version bump

0.0.1:
- initial release
Archived Files (1)
File Name
Version
Size
Uploader
Date
0.0.1
932B
zelenin
10/13/20 02:48 PM


Post A Reply Comment Options
Unread 11/14/20, 10:33 AM  
zelenin
AddOn Author - Click to view AddOns

Forum posts: 7
File comments: 192
Uploads: 12
Originally Posted by Scootworks
Originally Posted by zelenin
Originally Posted by Scootworks
why don't you use LibAsync for that case?
The library allows you to trigger a task many times, but execute one time in a given time window.
The library will execute this task as many times as it will be triggered. So we will get ui freezes with a large amount of data (for example, a searchbox and a data list of 100,000 lines filtered every time you enter a letter into the searchbox)
thank you. but LibAsync can do that as well. That’s why I‘m asking
write me an example. i didn't see this in addon description
Report comment to moderator  
Reply With Quote
Unread 11/13/20, 12:41 PM  
Scootworks
 
Scootworks's Avatar
AddOn Author - Click to view AddOns

Forum posts: 312
File comments: 64
Uploads: 28
Originally Posted by zelenin
Originally Posted by Scootworks
why don't you use LibAsync for that case?
The library allows you to trigger a task many times, but execute one time in a given time window.
The library will execute this task as many times as it will be triggered. So we will get ui freezes with a large amount of data (for example, a searchbox and a data list of 100,000 lines filtered every time you enter a letter into the searchbox)
thank you. but LibAsync can do that as well. That’s why I‘m asking
Report comment to moderator  
Reply With Quote
Unread 11/08/20, 02:57 AM  
zelenin
AddOn Author - Click to view AddOns

Forum posts: 7
File comments: 192
Uploads: 12
Originally Posted by Scootworks
why don't you use LibAsync for that case?
The library allows you to trigger a task many times, but execute one time in a given time window.
The library will execute this task as many times as it will be triggered. So we will get ui freezes with a large amount of data (for example, a searchbox and a data list of 100,000 lines filtered every time you enter a letter into the searchbox)
Last edited by zelenin : 11/08/20 at 09:37 AM.
Report comment to moderator  
Reply With Quote
Unread 11/07/20, 02:52 PM  
Scootworks
 
Scootworks's Avatar
AddOn Author - Click to view AddOns

Forum posts: 312
File comments: 64
Uploads: 28
why don't you use LibAsync for that case?
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: