Code: Select all
local Messenger = {};
local subscriptions = {};
function Messenger.publish( message, ... )
for _, subscription in ipairs( subscriptions ) do
if subscription.message == message then
subscription.callback( ... );
end
end
end
function Messenger.observe( message, callback )
subscriptions[#subscriptions + 1] = { message = message, callback = callback };
end
return Messenger;
Subscriptions are added via:
Code: Select all
Messenger.observe( EVENT.GRAPH_UPDATE_CENTER, function( ... )
updateCenter( ... );
end)
Any idea how to extend my class accordingly? Or does anybody have a recommendation for a lib?