Originally Posted by Layback_
So, AceDB object doesn't necessarily be initialized via AceAddon's OnInitialize method?
|
Nope!
Here's how you would adapt the example from the
AceDB-3.0 documentation page to use it without AceAddon-3.0. Yellow parts are copied from the documentation:
Code:
-- declare defaults to be used in the DB
local defaults = {
profile = {
setting = true,
}
}
-- Here we set up event handling, which as a happy coincidence,
-- replicates 99% of what anyone uses AceEvent for in just 3 lines of code:
local MyAddon = CreateFrame("Frame", ADDON_NAME)
MyAddon:SetScript("OnEvent", function(self, event, ...)
return self[event](self, ...)
end)
-- Now we replicate the functionality of the OnInitialize method from
-- AceAddon-3.0 by registering for an event and declaring a function to handle it:
MyAddon:RegisterEvent("PLAYER_LOGIN")
function MyAddon:PLAYER_LOGIN()
-- Assuming the .toc says ## SavedVariables: MyAddonDB
self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
end