react-rails-hot-loader 0.2.0 → 0.3.0

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: 1e6ee8a9957ce7f6e9df6b341dfa21e5b49f10ec
4
- data.tar.gz: 6d466122e147e872cad1669c81b19714bc2cf2d3
3
+ metadata.gz: 6e83238b5557bc6c6decdb17fd085f2de6417ea7
4
+ data.tar.gz: cd502ba5a6f1628240806b4e87e2d9e6c6053769
5
5
  SHA512:
6
- metadata.gz: 848a2c1cafc5069bc511ae833a9a53c925b1eb896dea8c957b245bb71e1d6746a06b61d2edc7eaf24a50167f62c84fbbdb0930bbe72798671c7cd60cd7f59c1f
7
- data.tar.gz: 597fee6dc283a11a85752f981aa6fc724361140fc8c4afa454efdbd0f32223135b2f88cf59945336c6603040011683baa1c6585943e7a5f4e82208a4dc5edbfb
6
+ metadata.gz: 37f574e95527201e7a5ba90ec339867c6e925d6678d3c45eb80f341ba34dcec1240ce7f8b1b3b30d7d761ce3ab0d270acbe7861c112070fdee3e1eed5c7ed5e8
7
+ data.tar.gz: c7b8887ae4e57aa06e00be047b413630ebb7572362d3b3678af33bc70e358a88ce96c05f4a817f1a7ed9e438b2fd1c1628b32ef619af8774a043e722e51b715c
@@ -9,10 +9,17 @@ module React
9
9
 
10
10
  config.after_initialize do |app|
11
11
  ActionDispatch::Reloader.to_prepare do
12
- begin
13
- React::Rails::HotLoader.restart
14
- rescue StandardError => err
15
- React::Rails::HotLoader.error(err)
12
+ React::Rails::HotLoader.restart
13
+ end
14
+
15
+ if defined?(PhusionPassenger)
16
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
17
+ if forked
18
+ # We're in smart spawning mode.
19
+ React::Rails::HotLoader.restart
20
+ else
21
+ # We're in direct spawning mode. We don't need to do anything.
22
+ end
16
23
  end
17
24
  end
18
25
  end
@@ -14,7 +14,6 @@ module React
14
14
 
15
15
  # Restarts the server _if_ it has stopped
16
16
  def restart
17
- return if running?
18
17
  start
19
18
  rescue StandardError => err
20
19
  React::Rails::HotLoader.error(err)
@@ -22,10 +21,6 @@ module React
22
21
 
23
22
  private
24
23
 
25
- def running?
26
- @server_thread && @server_thread.alive?
27
- end
28
-
29
24
  def start
30
25
  @server_thread = Thread.new do
31
26
  begin
@@ -36,18 +31,14 @@ module React
36
31
  end
37
32
  end
38
33
 
34
+ # If the Rails server runs event machine already,
35
+ # don't run EventMachine again, instead hook in with `next_tick`
39
36
  def serve
40
- EM.run {
41
- React::Rails::HotLoader.log("starting WS server: ws://#{host}:#{port}")
42
-
43
- EM::WebSocket.run(host: host, port: port) do |ws|
44
- ws.onopen { React::Rails::HotLoader.log("opened a connection") }
45
- ws.onmessage { |msg| handle_message(ws, msg) }
46
- ws.onclose { React::Rails::HotLoader.log("closed a connection") }
47
- end
48
-
49
- React::Rails::HotLoader.log("started WS server")
50
- }
37
+ if already_has_event_machine_server?
38
+ EM.next_tick { run_websocket_server }
39
+ else
40
+ EM.run { run_websocket_server }
41
+ end
51
42
  end
52
43
 
53
44
  # Check for any changes since `msg`, respond if there are any changes
@@ -62,6 +53,22 @@ module React
62
53
  rescue StandardError => err
63
54
  React::Rails::HotLoader.error(err)
64
55
  end
56
+
57
+ def run_websocket_server
58
+ React::Rails::HotLoader.log("starting WS server: ws://#{host}:#{port}")
59
+
60
+ EM::WebSocket.run(host: host, port: port) do |ws|
61
+ ws.onopen { React::Rails::HotLoader.log("opened a connection") }
62
+ ws.onmessage { |msg| handle_message(ws, msg) }
63
+ ws.onclose { React::Rails::HotLoader.log("closed a connection") }
64
+ end
65
+
66
+ React::Rails::HotLoader.log("started WS server")
67
+ end
68
+
69
+ def already_has_event_machine_server?
70
+ defined?(Thin)
71
+ end
65
72
  end
66
73
  end
67
74
  end
@@ -1,7 +1,7 @@
1
1
  module React
2
2
  module Rails
3
3
  module HotLoader
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
6
6
  end
7
7
  end
@@ -31,5 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "minitest"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
33
33
  spec.add_development_dependency "sqlite3"
34
+ spec.add_development_dependency "thin"
34
35
  spec.add_development_dependency "websocket-client-simple"
35
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-rails-hot-loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-15 00:00:00.000000000 Z
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: thin
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: websocket-client-simple
169
183
  requirement: !ruby/object:Gem::Requirement