clearwater-hot_loader 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 333c55823d1f8bf36570a9c7bc530669c4c0ebbe
4
- data.tar.gz: 980439c4b1b380b0d3842967fed45521e4ba1d5a
2
+ SHA256:
3
+ metadata.gz: 88069316bdc48d8c2d56ae1af915ff36127831e25c3b884e5ec59bebd730428f
4
+ data.tar.gz: 96ebbfda995dcf51cfb523eaeefa3d861c087367522db6a46619bc7bc85be8fa
5
5
  SHA512:
6
- metadata.gz: 2c16c3a63ba346cbb7c55e3680966c3d4a166c934de41a7db7635062f8a1fb2b85f83a4a796586dd07bd5651d3beb33ba7fdf0cd619c5edda12625e6ea982eca
7
- data.tar.gz: 7472c8d1a662ced9691399abdd481a5a007a1bba8e94bfa142ed9f7107bc3b9628d4d48e457547ef9795ffd8b483013f90f5557a90b4badf7fef33fc81bd50d1
6
+ metadata.gz: 2aa35a5fa937a07754305a46097f3aa9e24771cc369477beece437cd7156dc774a565658624d72fee52b89ac2ebf5bbbcb54bd23c2ea8da1c68ad1dee9fd92a6
7
+ data.tar.gz: 8df849b68d530b6bf8bfb43943a7901890b42c51717ffbcfa62c35a1a2ab9ff8370b4fe6c883b5437ad5b667cc5150ff6df66be9baced83c5d5546c533b386d4
@@ -1,5 +1,5 @@
1
1
  module Clearwater
2
2
  module HotLoader
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -6,11 +6,15 @@ module Clearwater
6
6
  class HotLoader
7
7
  attr_reader :port, :path
8
8
 
9
- def self.connect port=3000, path='/clearwater_hot_loader'
10
- new(port, path).connect
9
+ def self.connect port=nil, deprecated_path=nil, path: '/clearwater_hot_loader'
10
+ if deprecated_path
11
+ warn "[Clearwater::HotLoader] Passing the path as a positional argument is deprecated. Please pass the path as a keyword argument."
12
+ end
13
+
14
+ new(port, path: deprecated_path || path).connect
11
15
  end
12
16
 
13
- def initialize port, path='/clearwater_hot_loader'
17
+ def initialize port=nil, path: '/clearwater_hot_loader'
14
18
  @port = port
15
19
  @path = path
16
20
  Bowser.window.animation_frame do
@@ -25,7 +29,10 @@ module Clearwater
25
29
  end
26
30
 
27
31
  def connect
28
- @socket = Bowser::WebSocket.new("ws://localhost:#{port}#{path}")
32
+ match, scheme, host, port, = *Bowser.window.location.href.match(%r{(https?)://([^:/]+)(?:\:(\d+))?/?([^\?]*)})
33
+ port = @port if @port
34
+ socket_url = "ws#{'s' if scheme == 'https'}://#{host}#{":#{port}" if port}#{path}"
35
+ @socket = Bowser::WebSocket.new(socket_url)
29
36
 
30
37
  @socket.on :open do
31
38
  @app.render
@@ -34,11 +41,17 @@ module Clearwater
34
41
  @socket.on :message do |msg|
35
42
  begin
36
43
  %x{ eval(msg.native.data) }
44
+
45
+ # We need to perform the renders synchronously so we can rescue
46
+ # exceptions, but the app registry doesn't give us a way to do that,
47
+ # so we reach in and do this manually. Don't try this at home.
48
+ Clearwater::Application::AppRegistry
49
+ .instance_exec { @apps }
50
+ .each { |app| app.perform_render }
37
51
  rescue => e
38
52
  error_message = "[Clearwater::HotLoader] Error #{e.class}: #{e.message}"
39
53
  `console.error(error_message)`
40
54
  end
41
- Clearwater::Application.render
42
55
  end
43
56
 
44
57
  @socket.on :close do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearwater-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
  - Jamie Gaskins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clearwater
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.6.11
139
+ rubygems_version: 2.7.2
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Reload your Clearwater app without refreshing the browser