Class: Shoes::Linkable
- Inherits:
-
Object
- Object
- Shoes::Linkable
- 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.
Direct Known Subclasses
Niente::Drawable, Scarpe::Webview::ContainedService, Scarpe::Webview::Drawable, Drawable
Instance Attribute Summary collapse
-
#linkable_id ⇒ Object
readonly
Returns the value of attribute linkable_id.
Instance Method Summary collapse
- #bind_shoes_event(event_name:, target: nil, &handler) ⇒ Object
-
#initialize(linkable_id: object_id) ⇒ Linkable
constructor
A new instance of Linkable.
- #send_self_event(*args, event_name:, **kwargs) ⇒ Object
- #send_shoes_event(*args, event_name:, target: nil, **kwargs) ⇒ Object
- #unsub_all_shoes_events ⇒ Object
- #unsub_shoes_event(unsub_id) ⇒ Object
Constructor Details
#initialize(linkable_id: object_id) ⇒ Linkable
Returns a new instance of 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 (readonly)
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 |