makotok / Hanappe

Hanappe is a game framework for MOAI SDK.
Other
107 stars 41 forks source link

Remove Event:setListener() #91

Closed superquadratic closed 11 years ago

superquadratic commented 11 years ago

Maybe I overlooked something, but to me it seems like Event:setListener() is not really needed anymore. Would it be OK to remove it or does anyone use the callback and source properties of the Event object?

makotok commented 11 years ago

Implementation initially, I was thinking how to use the following.

local function onTest(e)
    print("hello!")
    e.target:removeEventListener(e.type, e.callback)
end

local obj = EventDispatcher()
obj:addEventListener("test", onTest)
obj:dispatchEvent("test")

If you want to remove an event listener, you can retrieve the information from the Event object. However, I do not know there are people who have this help.

makotok commented 11 years ago

This process is still necessary. That compatibility is lost is also a worry.

local button = widget.Button {
    size = {200, 50},
    text = "Hello",
    onClick = function(e)
        print("Hello")
        e.target:removeEventListener(e.type, e.callback)
    end,
}
superquadratic commented 11 years ago

That makes perfect sense, let's leave it as it is then!