Skip to content

Commit

Permalink
♻️ Moved up saved variable initialization to prevent any asynchronous…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
AssisrMatheus committed Sep 16, 2019
1 parent 14a03dc commit 987e976
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions components/TodoChecklister.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ end
--------------------------------------
function TodoChecklisterFrame:OnUpdate()
local scrollFrame = TodoItemsScrollFrame
local list = TodoChecklisterDB or {}
if (scrollFrame and scrollFrame.buttons and list) then
if (scrollFrame and scrollFrame.buttons and TodoChecklisterDB) then
local offset = HybridScrollFrame_GetOffset(scrollFrame)

if (#list > 0) then
if (#TodoChecklisterDB > 0) then
self.frame.Background.BlankText:SetText('')
else
self.frame.Background.BlankText:SetText('Oh no! \r\n You have no items on your list \r\n\r\n Start by typing them in the box above \r\n\r\n =)')
Expand All @@ -63,8 +62,8 @@ function TodoChecklisterFrame:OnUpdate()
local idx = i + offset
local button = scrollFrame.buttons[i]

if ( idx <= #list ) then
local todoItem = list[idx]
if ( idx <= #TodoChecklisterDB ) then
local todoItem = TodoChecklisterDB[idx]
button.todoItem = todoItem

-- Update button values
Expand All @@ -85,7 +84,7 @@ function TodoChecklisterFrame:OnUpdate()
end
end

HybridScrollFrame_Update(scrollFrame, (scrollFrame.buttons[1]:GetHeight()) * #list, scrollFrame:GetHeight())
HybridScrollFrame_Update(scrollFrame, (scrollFrame.buttons[1]:GetHeight()) * #TodoChecklisterDB, scrollFrame:GetHeight())
end
end

Expand Down
4 changes: 4 additions & 0 deletions constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ core.Constants = {}; -- adds Config table to addon namespace

local Constants = core.Constants;

if (not TodoChecklisterDB) then
TodoChecklisterDB = {}
end

--------------------------------------
-- Defaults (usually a database!)
--------------------------------------
Expand Down
6 changes: 1 addition & 5 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ local addonName, core = ...; -- Namespace
-- WARNING: self keyword automatically becomes events frame!
function core:Init(event, name)
if (name ~= addonName) then return end

if (not TodoChecklisterDB) then
TodoChecklisterDB = {}
end

core.Debug:Init();
core.Chat:Init();
core.MinimapIcon:Init();

if (#TodoChecklisterDB > 0) then
if (TodoChecklisterDB and #TodoChecklisterDB > 0) then
local completedList = core.TableUtils:Filter(TodoChecklisterDB, function(x) return x.isChecked == true end)
local notList = core.TableUtils:Filter(TodoChecklisterDB, function(x) return x.isChecked == false end)

Expand Down

0 comments on commit 987e976

Please sign in to comment.