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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a867c114bf9d71275cc023f35c644944abe5decc
4
- data.tar.gz: 4d0c10c661b6180a2881e5d6fbac3a10d6b77e02
3
+ metadata.gz: 47fb312acca42d54d68707e7f9134a58ae699a0a
4
+ data.tar.gz: 90bc58274efecb1f3ee22f810989f57c5c0b6a90
5
5
  SHA512:
6
- metadata.gz: 267a9d178686be33693532036a2bd8919f2f15e362f6ab20df3f293c60070eee5b9988dfeb8097519077aafcb7a2f3cf523a1f6e20390d0b55e08478780f2ff3
7
- data.tar.gz: 637125fea8cf8526c70c7e84badc5b5587243d3fec496fc9aef8d45c96c530e883d54001e396005b418adea48143ea5e2beea114e66c74213f9d99186cb872e1
6
+ metadata.gz: 32c175d56c79786cd331e8230e22fbd30a8dc4ebc8ce89a5e849cfdad05f3a6c903d6fec4a68b515f8290a8e7d723ee9631b17b287454b4adcb89ed64e6d508a
7
+ data.tar.gz: e9e71336ab0590c037f2c3e187f3e9cd4c326a95b0b1d357d8fbafebaa154417c5922b362aeabae9914a56f97242642412154d7aca7c244be3ac208321641e60
data/Changelog.org CHANGED
@@ -1,3 +1,5 @@
1
+ * 0.1.5
2
+ - support hyperloop patching in Opal 0.11
1
3
  * 0.1.4
2
4
  - make alerts configurable via OpalHotReloader.alerts_off!/OpalHotReloader.alerts_on!
3
5
  * 0.1.3
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|s?[ac]ss)$}) do |modified, added, removed|
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"
@@ -1,3 +1,3 @@
1
1
  module OpalHotReloader
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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
- %x{
17
- ws = new WebSocket('ws://' + #{ws_url});
18
- // console.log(ws);
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) { React::Component.force_update! }
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
- puts "No framework detected"
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
- class ReactrbPatches
3
- # React.rb needs to be patched so the we don't keep adding callbacks
4
- def self.patch!
5
- module ::React
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
- module ::React
25
- module Callbacks
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
- end
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
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: 2017-03-29 00:00:00.000000000 Z
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