mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 02:16:43 +00:00
scrap widget inheritance
This commit is contained in:
@@ -3,26 +3,22 @@ local ROOT = (...):gsub('[^.]*$', '')
|
||||
local Base = require(ROOT .. 'base')
|
||||
local Hooker = require(ROOT .. 'hooker')
|
||||
|
||||
local Event = Base:extend { name = 'Event' }
|
||||
local Event = Base:extend({ name = 'Event' })
|
||||
|
||||
function Event:emit (target, data, defaultAction)
|
||||
while target do
|
||||
local handlers = rawget(target, 'eventHandlers')
|
||||
local callbacks = handlers and handlers[self.name]
|
||||
if callbacks then
|
||||
local result = callbacks(data or {})
|
||||
if result ~= nil then return result end
|
||||
end
|
||||
target = target.widgetClass
|
||||
local callbacks = self.registry[target]
|
||||
if not callbacks then
|
||||
if defaultAction then defaultAction() end
|
||||
return
|
||||
end
|
||||
local result = callbacks(data or {})
|
||||
if result ~= nil then return result end
|
||||
if defaultAction then defaultAction() end
|
||||
end
|
||||
|
||||
function Event:bind (target, callback)
|
||||
if not rawget(target, 'eventHandlers') then
|
||||
target.eventHandlers = {}
|
||||
end
|
||||
return Hooker.hook(target.eventHandlers, self.name, callback)
|
||||
local registry = self.registry
|
||||
return Hooker.hook(registry, target, callback)
|
||||
end
|
||||
|
||||
local eventNames = {
|
||||
@@ -34,7 +30,10 @@ local eventNames = {
|
||||
local weakKeyMeta = { __mode = 'k' }
|
||||
|
||||
for i, name in ipairs(eventNames) do
|
||||
Event[name] = Event:extend { name = name }
|
||||
Event[name] = Event:extend({
|
||||
name = name,
|
||||
registry = setmetatable({}, weakKeyMeta),
|
||||
})
|
||||
end
|
||||
|
||||
function Event.injectBinders (t)
|
||||
|
||||
Reference in New Issue
Block a user