Skip to content

Commit

Permalink
refactor: make the State module more ergonomic for initialization
Browse files Browse the repository at this point in the history
This change makes it easier to test. To use the state module a
downstream caller must now do "require('orgmode.state.state')()".
  • Loading branch information
PriceHiller committed Nov 2, 2023
1 parent 6161297 commit 281925c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lua/orgmode/state/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local State = { data = {}, _ctx = { loaded = false, curr_loader = nil } }

local cache_path = vim.fs.normalize(vim.fn.stdpath('cache') .. '/org-cache.json', { expand_env = false })
--- Returns the current State singleton
function State:new()
function State.new()
-- This is done so we can later iterate the 'data'
-- subtable cleanly and shove it into a cache
setmetatable(State, {
Expand All @@ -16,6 +16,7 @@ function State:new()
tbl.data[key] = value
end,
})
local self = State
-- Start trying to load the state from cache as part of initializing the state
self:load()
return self
Expand Down Expand Up @@ -96,4 +97,4 @@ function State:load()
return self._ctx.curr_loader
end

return State:new()
return State.new

0 comments on commit 281925c

Please sign in to comment.