Module: LiveCable::ObserverTracking
- Included in:
- Delegator, ModelObserver
- Defined in:
- lib/live_cable/observer_tracking.rb
Overview
Mixin for objects that need to track and notify observers of changes.
This module is included in both Delegator and ModelObserver to provide a consistent interface for attaching observers and notifying them of changes.
Architecture:
- Objects can have multiple observers attached
- Each observer is associated with a specific variable name
- When the object changes, all observers are notified
- Observers then mark their variables as dirty in their containers
Instance Method Summary collapse
-
#add_live_cable_observer(observer, variable) ⇒ void
Attach an observer to track changes to a specific variable.
- #initialize_clone(other) ⇒ Object
- #initialize_dup(other) ⇒ Object
-
#remove_live_cable_observer(observer, variable) ⇒ void
Remove an observer from tracking changes to a specific variable.
Instance Method Details
#add_live_cable_observer(observer, variable) ⇒ void
This method returns an undefined value.
Attach an observer to track changes to a specific variable. The same observer can be attached multiple times for different variables.
36 37 38 39 40 41 42 |
# File 'lib/live_cable/observer_tracking.rb', line 36 def add_live_cable_observer(observer, variable) observers = live_cable_observers_for(variable) unless observers.include?(observer) observers << observer end end |
#initialize_clone(other) ⇒ Object
59 60 61 62 |
# File 'lib/live_cable/observer_tracking.rb', line 59 def initialize_clone(other) super @live_cable_observers = {} end |
#initialize_dup(other) ⇒ Object
54 55 56 57 |
# File 'lib/live_cable/observer_tracking.rb', line 54 def initialize_dup(other) super @live_cable_observers = {} end |
#remove_live_cable_observer(observer, variable) ⇒ void
This method returns an undefined value.
Remove an observer from tracking changes to a specific variable.
49 50 51 52 |
# File 'lib/live_cable/observer_tracking.rb', line 49 def remove_live_cable_observer(observer, variable) observers = live_cable_observers_for(variable) observers.delete(observer) end |