Thread Tools Display Modes
Prev Previous Post   Next Post Next
08-31-16, 07:28 PM   #1
Xuerian
A Fallenroot Satyr
 
Xuerian's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 27
Simplified event handling via callbacks

Lots of the UI and nearly all addons do event handling, and many in similar ways. How about providing a streamlined way to do the same thing?

This wouldn't change how events work, but could perhaps provide ways to optimize event processing and would certainly provide a more straightforward way to interact with the event system.

Lua Code:
  1. -- Register a simple handler
  2. local function ourHandler(...)
  3.   print(...)
  4. end
  5. local cb = C_Events.RegisterCallback("EVENT_NAME", ourHandler)
  6.  
  7. -- Register a method handler
  8. local t = {}
  9. function t:EVENT_NAME(...)
  10.   print(...)
  11. end
  12. local cb = C_Events.RegisterCallback("EVENT_NAME", t)
  13.  
  14.  
  15. -- Register a specific method handler
  16. function t:EventHandler(...)
  17.   print(...)
  18. end
  19. local cb = C_Events.RegisterCallback("EVENT_NAME", t, "EventHandler")
  20.  
  21. -- Disable or enable handler (Enabled by default)
  22. cb:Disable()
  23. cb:Enable()
  24.  
  25. -- Release handler
  26. cb:Destroy()
  27.  
  28. -- Register a single-use handler, automatically Destroyed on first call
  29. local cb = C_Events.RegisterSingleCallack("EVENT_NAME", t)
  30.  
  31. -- And prematurely destroy it
  32. cb:Destroy()

Last edited by Xuerian : 09-10-16 at 07:58 PM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Wish List » Simplified event handling via callbacks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off