Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
Advertisement
Source: SharedXML\GlobalCallbackRegistry.lua

EventRegistry is a FrameXML utility library for handling callbacks, similar to CallbackHandler-1.0. It inherits from CallbackRegistryMixin

CallbackRegistry[]

EventRegistry[]

Details[]

  • There is a caveat, if one of the functions registered through the event registry takes too long to execute (script timeouts) then all the other callbacks for the same event in the registry may also not get executed.
  • EventRegistry events and their payload are shown in the Event Trace panel when triggered.
EventRegistry 01

Example[]

A common use case is to register for Blizzard callback events, for example when the Mount Journal is opened.

EventRegistry:RegisterCallback("MountJournal.OnShow", function()
	print("showed the mount journal")
end)

Registers two callbacks to a custom event.

local function a(ownerID, ...)
	print("a", ...) -- prints "a", "foo", "bar"
end

local function b(ownerID, ...)
	print("b", ...) -- prints "b", "foo", "bar"
end

EventRegistry:RegisterCallback("HelloWorld.OnSomething", a)
EventRegistry:RegisterCallback("HelloWorld.OnSomething", b)

-- /run EventRegistry:TriggerEvent("HelloWorld.OnSomething", "foo", "bar")

Unregistering[]

Callbacks are unregistered by owner handle. When registering a callback the owner can be a table, function or string; if omitted it will be assigned an internal number.[1]

local cb = function(ownerID, journal, tabID)
	print("switched to collections tab", tabID)
end

local ownerID = EventRegistry:RegisterCallback("CollectionsJournal.TabSet", cb) -- omitted owner param

Example = ownerID
-- /run EventRegistry:UnregisterCallback("CollectionsJournal.TabSet", Example)

Frame Events[]

This allows you to respond to events without having to create a frame and registering an event to it.

EventRegistry:RegisterFrameEventAndCallback("PLAYER_ENTERING_WORLD", function(ownerID, ...)
	print(...) -- on login this prints: "foo", "bar", true, false
end, nil, "foo", "bar")

Private CallbackRegistry[]

Creates your own CallbackRegistry object instead of using EventRegistry.

local cr = CreateFromMixins(CallbackRegistryMixin)
cr:OnLoad()
cr:SetUndefinedEventsAllowed(true)
cr:RegisterCallback("MyCustomEvent", function(ownerID, ...)
	print("a", ...) -- prints "a", "foo", "bar"
end)

Example = cr
-- /run Example:TriggerEvent("MyCustomEvent", "foo", "bar")

External links[]

 GitHub Octocat Search FrameXML for TriggerEvent

Advertisement