WoW CallbackHandler-1.0 addon Shadowlands/Burning Crusade Classic 2021
logo
wow addon CallbackHandler-1.0

CallbackHandler-1.0

Game Version: 8.0.1
Total Downloads: 496,517
Updated: Jul 21, 2018
Created: Sep 29, 2008
download CallbackHandler-1.0Download Earlier Versions

Earlier Versions

Name Size Uploaded Game Version Downloads
1.0.8 release 4.49 KB Jul 21, 2018 8.0.1 84,991 download CallbackHandler-1.0 1.0.8 releaseDownload
1.0.6.70000 release 4.84 KB Jul 19, 2016 7.0.3 133,188 download CallbackHandler-1.0 1.0.6.70000 releaseDownload
1.0.6.60000 release 4.97 KB Oct 16, 2014 6.0.2 93,089 download CallbackHandler-1.0 1.0.6.60000 releaseDownload
r18 release 4.83 KB Oct 16, 2014 6.0.2 327 download CallbackHandler-1.0 r18 releaseDownload
1.0.6 release 5.04 KB Aug 9, 2010 3.3.5 161,279 download CallbackHandler-1.0 1.0.6 releaseDownload
1.0.5 release 5.06 KB Sep 17, 2009 3.2.0 5,443 download CallbackHandler-1.0 1.0.5 releaseDownload
1.0.3.30100 release 5.14 KB May 9, 2009 3.1.0 10,399 download CallbackHandler-1.0 1.0.3.30100 releaseDownload
1.0.3 release 4.87 KB Sep 29, 2008 3.0.2 4,707 download CallbackHandler-1.0 1.0.3 releaseDownload
r23-alpha alpha 4.49 KB Jul 21, 2018 8.0.1 156 download CallbackHandler-1.0 r23-alpha alphaDownload
r22-alpha alpha 4.15 KB Jul 21, 2018 7.0.3 82 download CallbackHandler-1.0 r22-alpha alphaDownload
r20 alpha 4.78 KB Jul 19, 2016 7.0.3 285 download CallbackHandler-1.0 r20 alphaDownload
r16 alpha 4.87 KB Jan 14, 2011 4.0.3a 351 download CallbackHandler-1.0 r16 alphaDownload
r14 alpha 5.00 KB Aug 9, 2010 3.3.5 191 download CallbackHandler-1.0 r14 alphaDownload
r13 alpha 4.95 KB Dec 6, 2009 3.2.0 640 download CallbackHandler-1.0 r13 alphaDownload
r12 alpha 4.79 KB Nov 2, 2009 3.2.0 228 download CallbackHandler-1.0 r12 alphaDownload
r10 alpha 5.03 KB Sep 17, 2009 3.2.0 105 download CallbackHandler-1.0 r10 alphaDownload
r9 alpha 5.25 KB Sep 17, 2009 3.2.0 127 download CallbackHandler-1.0 r9 alphaDownload
r8 alpha 5.23 KB Sep 16, 2009 3.2.0 154 download CallbackHandler-1.0 r8 alphaDownload
r7 alpha 5.19 KB Sep 16, 2009 3.1.0 160 download CallbackHandler-1.0 r7 alphaDownload
r5 alpha 5.08 KB May 9, 2009 3.1.0 118 download CallbackHandler-1.0 r5 alphaDownload
r3 alpha 4.83 KB Sep 29, 2008 2.4.3 497 download CallbackHandler-1.0 r3 alphaDownload

Description

Share this:

CallbackHandler is a back-end utility library that makes it easy for a library to fire its events to interested parties. It removes the need for addons to be aware of e.g. AceEvent.

The one remaining use for AceEvent Messages is messages that do not have a fixed source – ones that multiple libraries or addons can fire.

Including CallbackHandler-1.0 into your project

Are you a Library?

if using the WoWAce repositories

  • setup an external pointing to svn://svn.wowace.com/wow/callbackhandler/mainline/trunk/CallbackHandler-1.0 in the .pkgmeta file
  • disable nolib creation by adding enable-nolib-creation: no to the .pkgmeta file
  • set up your <library>.toc file to load CallbackHandler-1.0.xml (in case you support stand alone loading of the lib)
  • don't load CallbackHandler-1.0 via the .xml file ment for embedded loading of your lib
  • don't set CallbackHandler-1.0 as X-embeded or OptDep

otherwise

  • get a copy of the current version
  • copy CallbackHandler-1.0.lua into your library's folder
  • set up your <library>.toc file to load CallbackHandler-1.0.lua (in case you support stand alone loading of the lib)
  • don't load CallbackHandler-1.0 via the .xml file meant for embedded loading of your lib
  • don't set CallbackHandler-1.0 as X-embeded or OptDep

Are you an AddOn?

if using the WoWAce repositories

  • set up an external pointing to svn://svn.wowace.com/wow/callbackhandler/mainline/trunk/CallbackHandler-1.0 in the .pkgmeta file
  • set up your <addon>.toc or embeds.xml file to load CallbackHandler-1.0.xml
  • don't set CallbackHandler-1.0 as X-embeded or OptDep

otherwise

  • get a copy of the current version
  • copy CallbackHandler-1.0.lua into your addon's folder or a subfolder of it
  • set up your <addon>.toc or embeds.xml file to load CallbackHandler-1.0.lua
  • don't set CallbackHandler-1.0 as X-embeded or OptDep

Mixing in the CallbackHandler functions in your library or AddOn

MyLib.callbacks = MyLib.callbacks or 
    LibStub("CallbackHandler-1.0"):New(MyLib)

This adds 3 methods to your library:

  • MyLib.RegisterCallback(self, "eventName"[, method, [arg]])
  • MyLib.UnregisterCallback(self, "eventname")
  • MyLib.UnregisterAllCallbacks(self)

Make sure that the passed in self is your addon, and not the library itself, so the double-colon syntax will not work.

The MyLib.callbacks object is the callback registry itself, which you need to keep track of across in-game upgrades of your own library. (You do make sure that your library upgrades gracefully, right? 😉 )


Firing events

Assuming your callback registry is "MyLib.callbacks", firing named events is as easy as:

MyLib.callbacks:Fire("EventName", arg1, arg2, ...)

All arguments supplied to :Fire() are passed to the functions listening to the event.


Advanced uses

Renaming the methods

You can specify your own names for the methods installed by CallbackHandler:

MyLib.callbacks= MyLib.callbacks or 
    LibStub("CallbackHandler-1.0"):New(MyLib, 
        "MyRegisterFunc", 
        "MyUnregisterFunc", 
        "MyUnregisterAllFunc" or false
    )

Giving false as the name for "UnregisterAll" means that you do not want to give users access to that API at all – it will not be installed.

Tracking events being used

In some cases, it makes sense to know which events are being requested by your users. Perhaps to enable/disable code needed to track them.

CallbackHandler will always call callbacks:OnUsed() and :OnUnused() when an event starts/stops being used:

function MyLib.callbacks:OnUsed(target, eventname)
    -- "target" is == MyLib here
    print("Someone just registered for "..eventname.."!")
end

function MyLib.callbacks:OnUnused(target, eventname)
    print("Noone wants "..eventname.." any more")
end

"OnUsed" is only called if the event was previously unused. "OnUnused" is only called when the last user unregisters from an event. In other words, you won't see an "OnUnused" unless "OnUsed" has been called for an event. And you won't ever see two "OnUsed" in a row without "OnUnused" in between for an event.

Multiple event registries

As you may or may not know, CallbackHandler is the workhorse of AceEvent-3.0. It is used twice in AceEvent: once for in-game events, which cannot be fired by users, and once for "messages", which can be fired by users.

Providing multiple registries in AceEvent was as easy as:

AceEvent.events = AceEvent.events or 
    LibStub("CallbackHandler-1.0"):New(AceEvent, 
        "RegisterEvent", "UnregisterEvent", "UnregisterAllEvents"
    )

AceEvent.messages = AceEvent.messages or 
    LibStub("CallbackHandler-1.0"):New(AceEvent, 
        "RegisterMessage", "UnregisterMessage", "UnregisterAllMessages"
    )

AceEvent.SendMessage = AceEvent.messages.Fire

Of course, there is also some code in AceEvent to do the actual driving of in-game events (using OnUsed and OnUnused), but this is really the core of it.

Sorry

If the code examples above look mucked up, it's because AddonsWoW are still using the CSS style "white-space:normal;" when they should be using "white-space: pre-wrap;" for their <pre> HTML tags. /Mikk, november 2019

Comments

Add a comment