CallbackHandler-1.0

1 - Improving CallbackHandler

Nevcairiel and Mikk:

I'm developing a library which I would like to use CallbackHandler for tracing custom events. Although it's possible to implement it with the current version, I realized that it could be much easier to use if the need to set the callbacks registry as a variable were removed. I mean, it is only needed for "Fire", "OnUsed" and "OnUnused", and I think that there are better alternatives than the current one.
I would like to share my ideas, so, if you're interested, just let me know.

Best regards,
Jaliborc

User When Change
Jaliborc Sun, 01 Feb 2009 10:10:55 Changed status from Waiting to Replied
mikk Sun, 01 Feb 2009 07:28:44 Changed status from New to Waiting
Jaliborc Sun, 01 Feb 2009 00:26:31 Create

You must login to post a comment. Don't have an account? Register to get one!

  • 4 comments
  • Avatar of mikk mikk Mon, 03 Aug 2009 02:02:04

    Dohh, I lost mail tracking for this and never saw your response.

    No, I don't like your proposed changes.

    The OnUsed/OnUnused are currently called unprotected, which makes them fast. If you want, you can always fire callbacks yourself in your own registry.

    Always installing "Fire" in the destination object makes no sense - it makes it reachable by public sources, which in 99% of cases is not desirable.

  • Avatar of Jaliborc Jaliborc Mon, 09 Feb 2009 20:03:05

    So, which is your opinion?

  • Avatar of Jaliborc Jaliborc Sun, 01 Feb 2009 10:10:55

    To "get rid" of the registry, we only need to find alternatives for the "Fire", "OnUsed" and "OnUnused".

    Used/Unused
    Currently, Used and Unused are treated as functions indexed into the registry. I think that they could be treated as callbacks:

    LibStub("CallbackHandler-1.0"):New(MyObject)
    MyObject:RegisterCallback("OnUsed", --whatever we want here)
    MyObject.RegisterCallback(OtherObject, "OnUsed", --whatever)
    
    MyObject:RegisterCallback("MyCallBack", --whatever)
    MyObject.RegisterCallback(OtherObject, "OtherCallBack", --whatever)
    

    Registering callbacks from the MyObject ("MyCallBack" and "OtherCallBack") repository would fire the "OnUsed" callback. Unregistering them would fire "Unused". Of course, registering or unregistering "OnUsed" wouldn't fire itself, neither would "Unused".

    Fire
    Why was "Fire" placed in the registry? I could never understand. Probably because CallbackHandler was primary designed for AceEvent. Anyway, I think that "Fire" should be treated as "RegisterCallback", "UnregisterCallback" and "UnregisterAllCallbacks":

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

    In the case of AceEvent, blocking the "FireEvent" could be done easily:

    LibStub("CallbackHandler-1.0"):New(AceEvent, "RegisterEvent", "UnregisterEvent", "UnregisterAllEvents", "FireEvent")
    
    local FireEvent = AceEvent. FireEvent
    AceEvent. FireEvent = nil
    

    if you don't like the idea, making a new callback could also return the fire callback (but I think this option makes less sense)

    local FireEvent = LibStub("CallbackHandler-1.0"):New(AceEvent, "RegisterEvent", "UnregisterEvent", "UnregisterAllEvents", "FireEvent")
    AceEvent. FireEvent = nil
    

    Updating Embeds
    Unlike all AceEvent libraries, CallbackHandler doesn't update embeds. I think that this could be solved by indexing the "Register", "Unregister", "UnregisterAll" and "Fire" into the library itself, and then indexing into the embeds functions that would simply call the first ones.
    So, instead of (line 117):

    target[RegisterName] = function(self, eventname, method, ...)
                 [...]
    end
    

    We would first set a Register function

    function CallbackHandler.Register(registry, self, eventname, method, ...)
                 [...]
    end
    

    And then, when creating new registries:

    target[RegisterName] = function(...)
         return CallbackHandler.Register(registry, ...)
    end
    

    As the "real" functions are indexed into the library itself, CallbackHandler will only need to index them again to update all embeds.

    I hope I've been useful!
    Jaliborc

  • Avatar of mikk mikk Sun, 01 Feb 2009 07:28:38

    We're listening - do explain away.

  • 4 comments

Facts

Last updated on
03 Aug 2009
Reported on
01 Feb 2009
Status
Replied - Someone has replied after waiting for more information.
Type
Enhancement - A change which is intended to better the project in some way
Priority
Medium - Normal priority.

Reported by

Possible assignees

Votes (Total: -3, Average: -3.0)