feat: refactor to state
This commit is contained in:
parent
039fad1614
commit
7352189339
2 changed files with 83 additions and 2 deletions
|
|
@ -715,7 +715,7 @@ local function setup_contest(contest_id, language)
|
|||
logger.log('all problems already cached')
|
||||
end
|
||||
|
||||
state.contest_id = contest_id
|
||||
state.set_contest_id(contest_id)
|
||||
setup_problem(contest_id, problems[1].id, language)
|
||||
|
||||
return true
|
||||
|
|
@ -1019,7 +1019,7 @@ function M.handle_command(opts)
|
|||
|
||||
if cmd.type == 'full_setup' then
|
||||
if set_platform(cmd.platform) then
|
||||
state.contest_id = cmd.contest
|
||||
state.set_contest_id(cmd.contest)
|
||||
local problem_ids = {}
|
||||
local has_metadata = false
|
||||
|
||||
|
|
|
|||
81
lua/cp/state.lua
Normal file
81
lua/cp/state.lua
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
local M = {}
|
||||
|
||||
local state = {
|
||||
platform = nil,
|
||||
contest_id = nil,
|
||||
problem_id = nil,
|
||||
test_cases = nil,
|
||||
run_panel_active = false,
|
||||
saved_session = nil,
|
||||
}
|
||||
|
||||
function M.get_platform()
|
||||
return state.platform
|
||||
end
|
||||
|
||||
function M.set_platform(platform)
|
||||
state.platform = platform
|
||||
end
|
||||
|
||||
function M.get_contest_id()
|
||||
return state.contest_id
|
||||
end
|
||||
|
||||
function M.set_contest_id(contest_id)
|
||||
state.contest_id = contest_id
|
||||
end
|
||||
|
||||
function M.get_problem_id()
|
||||
return state.problem_id
|
||||
end
|
||||
|
||||
function M.set_problem_id(problem_id)
|
||||
state.problem_id = problem_id
|
||||
end
|
||||
|
||||
function M.get_test_cases()
|
||||
return state.test_cases
|
||||
end
|
||||
|
||||
function M.set_test_cases(test_cases)
|
||||
state.test_cases = test_cases
|
||||
end
|
||||
|
||||
function M.is_run_panel_active()
|
||||
return state.run_panel_active
|
||||
end
|
||||
|
||||
function M.set_run_panel_active(active)
|
||||
state.run_panel_active = active
|
||||
end
|
||||
|
||||
function M.get_saved_session()
|
||||
return state.saved_session
|
||||
end
|
||||
|
||||
function M.set_saved_session(session)
|
||||
state.saved_session = session
|
||||
end
|
||||
|
||||
function M.get_context()
|
||||
return {
|
||||
platform = state.platform,
|
||||
contest_id = state.contest_id,
|
||||
problem_id = state.problem_id,
|
||||
}
|
||||
end
|
||||
|
||||
function M.has_context()
|
||||
return state.platform and state.contest_id
|
||||
end
|
||||
|
||||
function M.reset()
|
||||
state.platform = nil
|
||||
state.contest_id = nil
|
||||
state.problem_id = nil
|
||||
state.test_cases = nil
|
||||
state.run_panel_active = false
|
||||
state.saved_session = nil
|
||||
end
|
||||
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue