Class: Shoes::Linkable
- Inherits:
-
Object
show all
- Defined in:
- lacci/lib/shoes/display_service.rb
Overview
This is for objects that can be referred to via events, using their
IDs. There are also convenience functions for binding and sending
events.
Linkable objects may be event targets. Technically anything, linkable
or not, can be an event subscriber, but linkables get easy convenience
functions for subscription.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(linkable_id: object_id) ⇒ Linkable
214
215
216
217
|
# File 'lacci/lib/shoes/display_service.rb', line 214
def initialize(linkable_id: object_id)
@linkable_id = linkable_id
@subscriptions = {}
end
|
Instance Attribute Details
#linkable_id ⇒ Object
Returns the value of attribute linkable_id.
212
213
214
|
# File 'lacci/lib/shoes/display_service.rb', line 212
def linkable_id
@linkable_id
end
|
Instance Method Details
#bind_shoes_event(event_name:, target: nil, &handler) ⇒ Object
227
228
229
230
231
|
# File 'lacci/lib/shoes/display_service.rb', line 227
def bind_shoes_event(event_name:, target: nil, &handler)
sub = DisplayService.subscribe_to_event(event_name, target, &handler)
@subscriptions[sub] = true
sub
end
|
#send_self_event(*args, event_name:, **kwargs) ⇒ Object
219
220
221
|
# File 'lacci/lib/shoes/display_service.rb', line 219
def send_self_event(*args, event_name:, **kwargs)
DisplayService.dispatch_event(event_name, self.linkable_id, *args, **kwargs)
end
|
#send_shoes_event(*args, event_name:, target: nil, **kwargs) ⇒ Object
223
224
225
|
# File 'lacci/lib/shoes/display_service.rb', line 223
def send_shoes_event(*args, event_name:, target: nil, **kwargs)
DisplayService.dispatch_event(event_name, target, *args, **kwargs)
end
|
#unsub_all_shoes_events ⇒ Object
241
242
243
244
|
# File 'lacci/lib/shoes/display_service.rb', line 241
def unsub_all_shoes_events
@subscriptions.keys.each { |k| DisplayService.unsub_from_events(k) }
@subscriptions.clear
end
|
#unsub_shoes_event(unsub_id) ⇒ Object
233
234
235
236
237
238
239
|
# File 'lacci/lib/shoes/display_service.rb', line 233
def unsub_shoes_event(unsub_id)
unless @subscriptions[unsub_id]
$stderr.puts "Unsubscribing from event that isn't in subscriptions! #{unsub_id.inspect}"
end
DisplayService.unsub_from_events(unsub_id)
@subscriptions.delete unsub_id
end
|