Skip to content

Commit 5122008

Browse files
committed
feat: only expose functions after setup
1 parent edeb458 commit 5122008

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lua/devto-nvim/init.lua

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ end
9191

9292
local devto_au_group = vim.api.nvim_create_augroup("devto_autocmds", {})
9393

94+
--- Check if the API key is set before calling the callback
95+
--- @param callback function The function to call if the API key is set
96+
--- @return function
97+
local function check_api_middleware(callback)
98+
return function()
99+
check_api_key(callback)
100+
end
101+
end
102+
94103
--- Setup the plugin
95104
--- It will create the necessary autocommands
96105
--- @param opts? table<string, any> At the moment, it is not used
@@ -131,19 +140,11 @@ function M.setup(opts)
131140
if not api.key() then
132141
notify.error(NO_API_KEY_ERROR)
133142
end
134-
end
135143

136-
--- Check if the API key is set before calling the callback
137-
--- @param callback function The function to call if the API key is set
138-
--- @return function
139-
local function check_api_middleware(callback)
140-
return function()
141-
check_api_key(callback)
142-
end
144+
M.my_articles = check_api_middleware(my_articles)
145+
M.new_article = check_api_middleware(new_article)
146+
M.feed = check_api_middleware(feed.open)
147+
M.open_url = check_api_middleware(open_by_url)
143148
end
144149

145-
M.my_articles = check_api_middleware(my_articles)
146-
M.new_article = check_api_middleware(new_article)
147-
M.feed = check_api_middleware(feed.open)
148-
M.open_url = check_api_middleware(open_by_url)
149150
return M

0 commit comments

Comments
 (0)