-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: re-generate lookup using debouncer
- Loading branch information
1 parent
51ffe50
commit fa8d6e2
Showing
7 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local M = {} | ||
|
||
-- Usage: | ||
-- local debounce = create_debouncer() | ||
-- | ||
-- local function1 = function() print("Function 1 executed!") end | ||
-- local function2 = function() print("Function 2 executed!") end | ||
-- | ||
-- local debounced1 = debounce(function1, 300) | ||
-- local debounced2 = debounce(function2, 500) | ||
-- | ||
-- -- Now you can use debounced1 and debounced2 | ||
function M.create_debouncer() | ||
local timers = {} | ||
|
||
return function(func, delay) | ||
local key = tostring(func) | ||
return function(...) | ||
local args = { ... } | ||
if timers[key] then | ||
vim.fn.timer_stop(timers[key]) | ||
end | ||
timers[key] = vim.fn.timer_start(delay, function() | ||
func(unpack(args)) | ||
timers[key] = nil | ||
end) | ||
end | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters