Skip to content

Commit

Permalink
Move event dispatcher into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkub committed Dec 14, 2009
1 parent 054ee49 commit e28bf68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
20 changes: 6 additions & 14 deletions AddonTemplate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
local myname, ns = ...


-----------------------------
-- Event Handler --
-----------------------------

local f = CreateFrame("frame")
f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
f:RegisterEvent("ADDON_LOADED")


function f:ADDON_LOADED(event, addon)
ns:RegisterEvent("ADDON_LOADED")
function ns:ADDON_LOADED(event, addon)
if addon ~= myname then return end
ns.InitDB()
self:InitDB()

-- Do anything you need to do after addon has loaded

Expand All @@ -26,7 +18,7 @@ function f:ADDON_LOADED(event, addon)
end


function f:PLAYER_LOGIN()
function ns:PLAYER_LOGIN()
self:RegisterEvent("PLAYER_LOGOUT")

-- Do anything you need to do after the player has entered the world
Expand All @@ -36,7 +28,7 @@ function f:PLAYER_LOGIN()
end


function f:PLAYER_LOGOUT()
ns.FlushDB()
function ns:PLAYER_LOGOUT()
self:FlushDB()
-- Do anything you need to do as the player logs out
end
1 change: 1 addition & 0 deletions AddonTemplate.toc
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ Locale.lua
Database.lua
Slashcommand.lua
UtilityFunctions.lua
EventDispatcher.lua

AddonTemplate.lua
11 changes: 11 additions & 0 deletions EventDispatcher.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

local myname, ns = ...


local f = CreateFrame("frame")
f:SetScript("OnEvent", function(self, event, ...) if ns[event] then return ns[event](ns, event, ...) end end)


function ns:RegisterEvent(...) for i=1,select("#", ...) do f:RegisterEvent((select(i, ...))) end end
function ns:UnregisterEvent(...) for i=1,select("#", ...) do f:UnregisterEvent((select(i, ...))) end end
ns.RegisterEvents, ns.UnregisterEvents = ns.RegisterEvent, ns.UnregisterEvent

0 comments on commit e28bf68

Please sign in to comment.