mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-13 06:42:35 +00:00
44 lines
1.0 KiB
Ruby
44 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class IMICFPS
|
|
class Publisher
|
|
def self.subscribe(subscription)
|
|
raise "Expected IMICFPS::Subscription not #{subscription.class}" unless subscription.is_a?(IMICFPS::Subscription)
|
|
|
|
Publisher.instance.add_sub(subscription)
|
|
end
|
|
|
|
def self.unsubscribe(subscription)
|
|
end
|
|
|
|
def self.instance
|
|
@@instance
|
|
end
|
|
|
|
def initialize
|
|
@@instance = self
|
|
EventHandler.initiate
|
|
Component.initiate
|
|
@events = {}
|
|
end
|
|
|
|
def add_sub(subscription)
|
|
raise "Expected IMICFPS::Subscription not #{subscription.class}" unless subscription.is_a?(IMICFPS::Subscription)
|
|
|
|
@events[subscription.event] ||= []
|
|
|
|
@events[subscription.event] << subscription
|
|
end
|
|
|
|
def publish(event, context, *args)
|
|
if subscribers = @events[event]
|
|
return unless event_handler = EventHandler.get(event)
|
|
|
|
subscribers.each do |subscriber|
|
|
event_handler.handle(subscriber, context, args)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|