Module: Hotwire::Livereload
- Defined in:
- lib/hotwire/livereload.rb,
lib/hotwire/livereload/engine.rb,
lib/hotwire/livereload/version.rb
Defined Under Namespace
Modules: LivereloadTagsHelper
Classes: Engine, ReloadChannel
Constant Summary
collapse
- DISABLE_FILE =
"tmp/livereload-disabled.txt"
- VERSION =
"1.4.0"
Class Method Summary
collapse
Class Method Details
.action_cable(opts) ⇒ Object
112
113
114
|
# File 'lib/hotwire/livereload/engine.rb', line 112
def self.action_cable(opts)
ActionCable.server.broadcast("hotwire-reload", opts)
end
|
.debounce(wait_ms, &block) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/hotwire/livereload/engine.rb', line 123
def self.debounce(wait_ms, &block)
if wait_ms.zero?
return ->(*args) { yield(*args) }
end
mutex = Mutex.new
timer_thread = nil
seconds = wait_ms.to_f / 1000.0
lambda do |*args|
mutex.synchronize do
timer_thread&.kill
timer_thread = Thread.new do
sleep(seconds)
yield(*args)
end
end
end
end
|
.server_process? ⇒ Boolean
116
117
118
119
120
121
|
# File 'lib/hotwire/livereload/engine.rb', line 116
def self.server_process?
puma_process = defined?(::Puma) && File.basename($0) == "puma"
rails_server = defined?(Rails::Server)
puma_process || rails_server
end
|
.turbo_stream(locals) ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/hotwire/livereload/engine.rb', line 103
def self.turbo_stream(locals)
Turbo::StreamsChannel.broadcast_replace_to(
"hotwire-livereload",
target: "hotwire-livereload",
partial: "hotwire/livereload/turbo_stream",
locals: locals
)
end
|