feat(persistence): add pre- and post- load hooks (#24)

* Add optional hook typings to config object

* Add optional hooks conditional calls

* Add hooks description to main readme
This commit is contained in:
Roeeeee 2024-05-16 20:03:16 +03:00 committed by GitHub
parent 4982499c16
commit 3d443bd0a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

View file

@ -56,6 +56,10 @@ function M.start()
end
M.save()
if type(Config.options.post_save) == "function" then
Config.options.post_save()
end
end,
})
end
@ -76,7 +80,15 @@ function M.load(opt)
opt = opt or {}
local sfile = opt.last and M.get_last() or M.get_current()
if sfile and vim.fn.filereadable(sfile) ~= 0 then
if type(Config.options.pre_load) == "function" then
Config.options.pre_load()
end
vim.cmd("silent! source " .. e(sfile))
if type(Config.options.post_load) == "function" then
Config.options.post_load()
end
end
end