Module: LiveCable::Component::Lifecycle
- Extended by:
- ActiveSupport::Concern
- Included in:
- LiveCable::Component
- Defined in:
- lib/live_cable/component/lifecycle.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/live_cable/component/lifecycle.rb', line 58
def method_missing(method_name, *, &)
if channel.nil? || channel.connection.identifiers.exclude?(method_name)
return super
end
channel.connection.public_send(method_name, *, &)
end
|
Instance Method Details
#connect(channel) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/live_cable/component/lifecycle.rb', line 23
def connect(channel)
run_callbacks :connect do
@channel = channel
start_stream
@subscribed = true
end
end
|
#destroy ⇒ Object
44
45
46
47
48
49
|
# File 'lib/live_cable/component/lifecycle.rb', line 44
def destroy
broadcast_destroy
previous_render_context&.children&.map(&:destroy)
end
|
#disconnect ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/live_cable/component/lifecycle.rb', line 31
def disconnect
run_callbacks :disconnect do
stop_stream
@channel = nil
@previous_render_context&.clear
@previous_render_context = nil
end
ensure
live_connection&.remove_component(self)
@live_connection = nil
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
Allow the component to access the identified_by methods from the connection
52
53
54
55
56
|
# File 'lib/live_cable/component/lifecycle.rb', line 52
def respond_to_missing?(method_name, _include_private = false)
return false unless channel
channel.connection.identifiers.include?(method_name)
end
|
#status ⇒ Object
14
15
16
|
# File 'lib/live_cable/component/lifecycle.rb', line 14
def status
subscribed? ? 'subscribed' : 'disconnected'
end
|
#subscribed? ⇒ Boolean
18
19
20
|
# File 'lib/live_cable/component/lifecycle.rb', line 18
def subscribed?
@subscribed
end
|