Feature: 10.1.0 Group Callbacks
StormFX opened this issue ยท 0 comments
After adding the new Group callback API in 10.0.7
, I realized that it may be useful to allow authors to register callbacks for only certain events (IE, changes to specific settings via Masque's options). Therefore, version 10.1.0
includes changes to enable this behavior.
Callbacks can still be registered in the same way they were in 10.0.7
, however, now additional string parameters can be passed to target specific options. Some examples:
Before API_VERSION: 100100
:
local function myCallback(Group, Option, Value)
if Option == "Disabled" then
-- Do something.
end
end
local Group = Masque:Group("myAddon", "myGroup")
-- Note that this callback will be fired every time ANY option is changed and thus has to be filtered,
-- as demonstrated in the function above.
Group:RegisterCallback(myCallback)
After API_VERSION: 100100
:
local function myCallback(Group, Option, Value)
-- Do something.
end
local Group = Masque:Group("myAddon", "myGroup")
-- This callback will only be fired when the "Disabled" option is changed, so doesn't need to be filtered.
Group:RegisterCallback(myCallback, "Disabled")
The same logic can be applied when passing a method:
local myObj = {}
function myObj:myCallback(Group, Option, Value)
-- Do something.
end
local Group = Masque:Group("myAddon", "myGroup")
Group:RegisterCallback(myObj.myCallback, myObj, "Disabled")
Additionally, multiple events can be registered with the same function, though will have to be filtered:
local function myCallback(Group, Option, Value)
if Option == "Disabled" then
-- Do something.
elseif Option == "Reset" then
-- Do something else.
end
end
local Group = Masque:Group("myAddon", "myGroup")
Group:RegisterCallback(myCallback, "Disabled", "Reset")
The list of events/options can be found on the wiki page.
I'll try to put together a comprehensive article soon, but it may take me a bit. This, at least, should give a basic understanding of the changes.
P.S. The Register
API method and the SetCallback
Group method are both deprecated and no longer function (they'll throw out a warning once).