Skip to content

Commit fde5fee

Browse files
committed
refactor: refactored ui code
1 parent cd023dc commit fde5fee

File tree

4 files changed

+232
-178
lines changed

4 files changed

+232
-178
lines changed

Diff for: lua/lazy/core/util.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ function M.track(data, time)
2929
end
3030

3131
---@param name string
32+
---@return string
3233
function M.normname(name)
33-
return name:lower():gsub("^n?vim%-", ""):gsub("%.n?vim$", ""):gsub("%.lua", ""):gsub("[^a-z]+", "")
34+
local ret = name:lower():gsub("^n?vim%-", ""):gsub("%.n?vim$", ""):gsub("%.lua", ""):gsub("[^a-z]+", "")
35+
return ret
3436
end
3537

38+
---@return string
3639
function M.norm(path)
3740
if path:sub(1, 1) == "~" then
3841
local home = vim.loop.os_homedir()

Diff for: lua/lazy/util.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,29 @@ function M.write_file(file, contents)
4545
fd:close()
4646
end
4747

48+
---@generic F: fun()
4849
---@param ms number
49-
---@param fn fun()
50+
---@param fn F
51+
---@return F
5052
function M.throttle(ms, fn)
5153
local timer = vim.loop.new_timer()
5254
local running = false
5355
local first = true
5456

55-
return function()
57+
return function(...)
58+
local args = { ... }
59+
local wrapped = function()
60+
fn(unpack(args))
61+
end
5662
if not running then
5763
if first then
58-
fn()
64+
wrapped()
5965
first = false
6066
end
6167

6268
timer:start(ms, 0, function()
6369
running = false
64-
vim.schedule(fn)
70+
vim.schedule(wrapped)
6571
end)
6672

6773
running = true

0 commit comments

Comments
 (0)