diff --git a/itemcontroller.lua b/itemcontroller.lua index d9219b4..124bcc1 100644 --- a/itemcontroller.lua +++ b/itemcontroller.lua @@ -122,6 +122,15 @@ local function itemList(groups, wBudget, onClick) } end +local function updatePageRender(state, pages) + if state.nextPage ~= nil then + state.currentPage = state.nextPage + state.nextPage = nil + + state._pageRender = pages[state.currentPage](state) + end +end + local function renderDefault(state, rootElement) local event = {os.pullEvent()} local handled = rootElement:handleEvent(event) @@ -193,12 +202,6 @@ local CONTROLLER_STATE = { os.queueEvent("dummy_event") while not CONTROLLER_STATE.exit do - PAGES[CONTROLLER_STATE.currentPage](CONTROLLER_STATE) - - if CONTROLLER_STATE.nextPage ~= nil then - CONTROLLER_STATE.currentPage = CONTROLLER_STATE.nextPage - CONTROLLER_STATE.nextPage = nil - end - - sleep(0) + updatePageRender(CONTROLLER_STATE, PAGES) + CONTROLLER_STATE._pageRender() end \ No newline at end of file