Class: Takagi::Observable::Emitter
- Inherits:
-
Object
- Object
- Takagi::Observable::Emitter
- Defined in:
- lib/takagi/observable/emitter.rb
Overview
Emitter for push-based observable updates
Allows observables to push notifications immediately when data changes, rather than relying on polling intervals.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Emitter
constructor
A new instance of Emitter.
-
#notify(value) ⇒ void
Push a notification to all observers of this path.
-
#on_event(address) {|event| ... } ⇒ void
Subscribe to EventBus events and forward to observers.
Constructor Details
#initialize(path) ⇒ Emitter
Returns a new instance of Emitter.
26 27 28 |
# File 'lib/takagi/observable/emitter.rb', line 26 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
24 25 26 |
# File 'lib/takagi/observable/emitter.rb', line 24 def path @path end |
Instance Method Details
#notify(value) ⇒ void
This method returns an undefined value.
Push a notification to all observers of this path
37 38 39 |
# File 'lib/takagi/observable/emitter.rb', line 37 def notify(value) Takagi::Observer::Registry.notify(@path, value) end |
#on_event(address) {|event| ... } ⇒ void
This method returns an undefined value.
Subscribe to EventBus events and forward to observers
54 55 56 57 58 59 |
# File 'lib/takagi/observable/emitter.rb', line 54 def on_event(address, &transform) Takagi::EventBus.subscribe(address) do |event| value = transform ? transform.call(event) : event.data notify(value) end end |