opal_hot_reloader 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.org +2 -0
- data/README.md +1 -0
- data/images/reload_error.png +0 -0
- data/lib/opal_hot_reloader/server.rb +4 -4
- data/lib/opal_hot_reloader/version.rb +1 -1
- data/opal/opal_hot_reloader.rb +18 -12
- data/opal/opal_hot_reloader/reactrb_patches.rb +23 -52
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47fb312acca42d54d68707e7f9134a58ae699a0a
|
4
|
+
data.tar.gz: 90bc58274efecb1f3ee22f810989f57c5c0b6a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32c175d56c79786cd331e8230e22fbd30a8dc4ebc8ce89a5e849cfdad05f3a6c903d6fec4a68b515f8290a8e7d723ee9631b17b287454b4adcb89ed64e6d508a
|
7
|
+
data.tar.gz: e9e71336ab0590c037f2c3e187f3e9cd4c326a95b0b1d357d8fbafebaa154417c5922b362aeabae9914a56f97242642412154d7aca7c244be3ac208321641e60
|
data/Changelog.org
CHANGED
data/README.md
CHANGED
@@ -73,6 +73,7 @@ OpalHotReloader.listen
|
|
73
73
|
#### Alerts
|
74
74
|
|
75
75
|
![Reload Error Alert](images/reload_error.png)
|
76
|
+
|
76
77
|
By default, if there is an error hot loading code, opal_hot_reloader
|
77
78
|
will present an alert of the error. The following options can be used
|
78
79
|
to turn the alerts on and off:
|
Binary file
|
@@ -65,8 +65,8 @@ module OpalHotReloader
|
|
65
65
|
|
66
66
|
|
67
67
|
def send_updated_file(modified_file)
|
68
|
-
if modified_file =~ /\.rb
|
69
|
-
file_contents = File.read(modified_file)
|
68
|
+
if modified_file =~ /\.rb(\.erb)?$/
|
69
|
+
file_contents = File.read(modified_file).force_encoding(Encoding::UTF_8)
|
70
70
|
update = {
|
71
71
|
type: 'ruby',
|
72
72
|
filename: modified_file,
|
@@ -93,7 +93,7 @@ module OpalHotReloader
|
|
93
93
|
|
94
94
|
PROGRAM = 'opal-hot-reloader'
|
95
95
|
def loop
|
96
|
-
listener = Listen.to(*@directories, only: %r{\.(rb
|
96
|
+
listener = Listen.to(*@directories, only: %r{\.(rb(\.erb)?|s?[ac]ss)$}) do |modified, added, removed|
|
97
97
|
modified.each { |modified_file| send_updated_file(modified_file) }
|
98
98
|
puts "modified absolute path: #{modified}"
|
99
99
|
puts "added absolute path: #{added}"
|
@@ -108,7 +108,7 @@ module OpalHotReloader
|
|
108
108
|
puts "#{PROGRAM}: client open"
|
109
109
|
end
|
110
110
|
client.onmessage do |mess|
|
111
|
-
puts "PROGRAM: message received: #{mess}"
|
111
|
+
puts "PROGRAM: message received: #{mess}" unless mess == ''
|
112
112
|
end
|
113
113
|
client.onclose do
|
114
114
|
puts "#{PROGRAM}: client closed"
|
data/opal/opal_hot_reloader.rb
CHANGED
@@ -11,13 +11,12 @@ class OpalHotReloader
|
|
11
11
|
def connect_to_websocket(port)
|
12
12
|
host = `window.location.host`.sub(/:\d+/, '')
|
13
13
|
host = '127.0.0.1' if host == ''
|
14
|
+
protocol = `window.location.protocol` == 'https:' ? 'wss:' : 'ws:'
|
14
15
|
ws_url = "#{host}:#{port}"
|
15
16
|
puts "Hot-Reloader connecting to #{ws_url}"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
ws.onmessage = #{lambda { |e| reload(e) }}
|
20
|
-
}
|
17
|
+
ws = `new WebSocket(#{protocol} + '//' + #{ws_url})`
|
18
|
+
`#{ws}.onmessage = #{lambda { |e| reload(e) }}`
|
19
|
+
`setInterval(function() { #{ws}.send('') }, #{@ping * 1000})` if @ping
|
21
20
|
end
|
22
21
|
|
23
22
|
def notify_error(reload_request)
|
@@ -61,10 +60,11 @@ class OpalHotReloader
|
|
61
60
|
|
62
61
|
# @param port [Integer] opal hot reloader port to connect to
|
63
62
|
# @param reload_post_callback [Proc] optional callback to be called after re evaluating a file for example in react.rb files we want to do a React::Component.force_update!
|
64
|
-
def initialize(port=25222, &reload_post_callback)
|
63
|
+
def initialize(port=25222, ping=nil, &reload_post_callback)
|
65
64
|
@port = port
|
66
65
|
@reload_post_callback = reload_post_callback
|
67
66
|
@css_reloader = CssReloader.new
|
67
|
+
@ping = ping
|
68
68
|
end
|
69
69
|
# Opens a websocket connection that evaluates new files and runs the optional @reload_post_callback
|
70
70
|
def listen
|
@@ -74,22 +74,28 @@ end
|
|
74
74
|
# convenience method to start a listen w/one line
|
75
75
|
# @param port [Integer] opal hot reloader port to connect to. Defaults to 25222 to match opal-hot-loader default
|
76
76
|
# @deprecated reactrb - this flag no longer necessary and will be removed in gem release 0.2
|
77
|
-
def self.listen(port=25222, reactrb=false)
|
77
|
+
def self.listen(port=25222, reactrb=false, ping=nil)
|
78
78
|
return if @server
|
79
79
|
if reactrb
|
80
80
|
warn "OpalHotReloader.listen(#{port}): reactrb flag is deprectated and will be removed in gem release 0.2. React will automatically be detected"
|
81
81
|
end
|
82
|
-
create_framework_aware_server(port)
|
82
|
+
create_framework_aware_server(port, ping)
|
83
83
|
end
|
84
84
|
# Automatically add in framework specific hooks
|
85
85
|
|
86
|
-
def self.create_framework_aware_server(port)
|
86
|
+
def self.create_framework_aware_server(port, ping)
|
87
87
|
if defined? ::React
|
88
88
|
ReactrbPatches.patch!
|
89
|
-
@server = OpalHotReloader.new(port)
|
89
|
+
@server = OpalHotReloader.new(port, ping) do
|
90
|
+
if defined?(Hyperloop) &&
|
91
|
+
defined?(Hyperloop::ClientDrivers) &&
|
92
|
+
Hyperloop::ClientDrivers.respond_to?(:initialize_client_drivers_on_boot)
|
93
|
+
Hyperloop::ClientDrivers.initialize_client_drivers_on_boot
|
94
|
+
end
|
95
|
+
React::Component.force_update!
|
96
|
+
end
|
90
97
|
else
|
91
|
-
|
92
|
-
@server = OpalHotReloader.new(port)
|
98
|
+
@server = OpalHotReloader.new(port, ping)
|
93
99
|
end
|
94
100
|
@server.listen
|
95
101
|
end
|
@@ -1,60 +1,31 @@
|
|
1
1
|
# patches to support reloading react.rb
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module Callbacks
|
7
|
-
module ClassMethods
|
8
|
-
def define_callback(callback_name)
|
9
|
-
attribute_name = "_#{callback_name}_callbacks"
|
10
|
-
class_attribute(attribute_name)
|
11
|
-
self.send("#{attribute_name}=", [])
|
12
|
-
define_singleton_method(callback_name) do |*args, &block|
|
13
|
-
# puts "calling new and improved callbacks"
|
14
|
-
callbacks = []
|
15
|
-
callbacks.concat(args)
|
16
|
-
callbacks.push(block) if block_given?
|
17
|
-
self.send("#{attribute_name}=", callbacks)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
2
|
+
module ReactrbPatchModules
|
3
|
+
module ReactComponent
|
4
|
+
def add_to_global_component_list(instance)
|
5
|
+
(@global_component_list ||= Set.new).add instance
|
22
6
|
end
|
23
7
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
alias_method :original_run_callback, :run_callback
|
28
|
-
|
29
|
-
def run_callback(name, *args)
|
30
|
-
# monkey patch run callback because its easiest place to hook
|
31
|
-
# into all components lifecycles.
|
32
|
-
React::Component.add_to_global_component_list self if name == :before_mount
|
33
|
-
original_run_callback name, *args
|
34
|
-
React::Component.remove_from_global_component_list self if name == :before_unmount
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
module Component
|
40
|
-
|
41
|
-
def self.add_to_global_component_list instance
|
42
|
-
# puts "Adding #{instance} to component list"
|
43
|
-
(@global_component_list ||= Set.new).add instance
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.remove_from_global_component_list instance
|
47
|
-
# puts "Removing #{instance} from component list"
|
48
|
-
@global_component_list.delete instance
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.force_update!
|
52
|
-
# puts "Forcing global update"
|
53
|
-
@global_component_list && @global_component_list.each(&:force_update!)
|
54
|
-
end
|
8
|
+
def remove_from_global_component_list(instance)
|
9
|
+
@global_component_list.delete instance
|
10
|
+
end
|
55
11
|
|
56
|
-
|
12
|
+
def force_update!
|
13
|
+
@global_component_list && @global_component_list.each(&:force_update!)
|
57
14
|
end
|
15
|
+
end
|
16
|
+
end
|
58
17
|
|
18
|
+
class ReactrbPatches
|
19
|
+
# React.rb needs to be patched so the we don't keep adding callbacks
|
20
|
+
def self.patch!
|
21
|
+
::React::Component.extend ReactrbPatchModules::ReactComponent # works
|
22
|
+
|
23
|
+
::React::Callbacks.alias_method :original_run_callback, :run_callback # works
|
24
|
+
# Easiest place to hook into all components lifecycles
|
25
|
+
::React::Callbacks.define_method(:run_callback) do |name, *args| # works
|
26
|
+
React::Component.add_to_global_component_list self if name == :before_mount
|
27
|
+
original_run_callback name, *args
|
28
|
+
React::Component.remove_from_global_component_list self if name == :before_unmount
|
29
|
+
end
|
59
30
|
end
|
60
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal_hot_reloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Forrest Chang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- bin/console
|
116
116
|
- bin/opal-hot-reloader
|
117
117
|
- bin/setup
|
118
|
+
- images/reload_error.png
|
118
119
|
- lib/opal_hot_reloader.rb
|
119
120
|
- lib/opal_hot_reloader/server.rb
|
120
121
|
- lib/opal_hot_reloader/version.rb
|