Module: Frontman::DispatchEvents
- Extended by:
- T::Sig
- Included in:
- Builder::Builder
- Defined in:
- lib/frontman/concerns/dispatch_events.rb
Instance Method Summary collapse
-
#emit(events, *arguments) ⇒ Object
We don’t annotate with sig because of bad support for splat arguments.
- #listeners ⇒ Object
- #off(events) ⇒ Object
- #on(events, callback) ⇒ Object
Instance Method Details
#emit(events, *arguments) ⇒ Object
We don’t annotate with sig because of bad support for splat arguments
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/frontman/concerns/dispatch_events.rb', line 29 def emit(events, *arguments) list(events).each do |event_name| event_listeners = listeners[event_name.to_sym] || [] event_listeners.each do |listener| listener.call(*arguments) end end self end |
#listeners ⇒ Object
11 12 13 |
# File 'lib/frontman/concerns/dispatch_events.rb', line 11 def listeners @listeners ||= {} end |
#off(events) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/frontman/concerns/dispatch_events.rb', line 41 def off(events) list(events).each do |event_name| listeners[event_name.to_sym] = [] end self end |
#on(events, callback) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/frontman/concerns/dispatch_events.rb', line 19 def on(events, callback) list(events).each do |event_name| listeners[event_name.to_sym] ||= [] T.must(listeners[event_name.to_sym]).push(callback) end self end |