After some further testing it appears that the SpellMixin way of working isn't exactly the greatest. It's definitely lightweight but it doesn't work for unknown spells until a second call. However, the following seems to work everytime on a fresh login.
Lua Code:
--[[ Cache the on demand values ]]--
local function CacheSpellData(spellID)
addonData.SpellCache = {}
addonData.SpellCache[spellID] = {}
local id,fileID = GetSpellTexture(spellID)
local name = GetSpellInfo(spellID)
local isKnown = IsSpellKnown(spellID)
addonData.SpellCache[spellID].TextureID = fileID
addonData.SpellCache[spellID].Name = name
addonData.SpellCache[spellID].isKnown = isKnown
end
--[[ Get the required information for the spellID, if not cached, cache it ]]
function addonData:GetSpellInfo(spellID)
if not self.SpellCache[spellID] then
CacheSpellData(spellID)
end
local cache = self.SpellCache[spellID]
return cache.Name, cache.TextureID, cache.isKnown
end
--[[ Monitor for SpellCache Request Results ]]--
local function EventWatcher(self,event,...)
if event == "PLAYER_ENTERING_WORLD" then
for i,v in pairs(addonData.Spells) do
C_Spell.RequestLoadSpellData(i)
end
elseif event == "SPELL_DATA_LOAD_RESULT" then
local spellID,success = ...
if success and addonData.Spells[spellID] then
CacheSpellData(spellID)
end
end
end
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("SPELL_DATA_LOAD_RESULT")
f:SetScript("OnEvent", EventWatcher)