clearwater-hot_loader 0.1.0 → 0.2.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: 62c2fa540fc31b83554e87857a0fa030fb28fd5f
4
- data.tar.gz: 48acf0cb240586d81b00f681810731c149eaf75a
3
+ metadata.gz: 333c55823d1f8bf36570a9c7bc530669c4c0ebbe
4
+ data.tar.gz: 980439c4b1b380b0d3842967fed45521e4ba1d5a
5
5
  SHA512:
6
- metadata.gz: 5eb6383c99d0897ba6f5dc9cd910c5657866d7bae1c9672b1e2d7b6091802b22eda30004d3fd22411e0da6b2c332c63bbf5c8f093fe311682c7946c5f25c088d
7
- data.tar.gz: 549ef88113da09433a95cdc7b6a0cd0d2402550994dde6ab4d70ee39c14b3c18e26b6c4b139bbee7764755a6c93514ffe3134e751de2ea292ce85c612ae8cfaa
6
+ metadata.gz: 2c16c3a63ba346cbb7c55e3680966c3d4a166c934de41a7db7635062f8a1fb2b85f83a4a796586dd07bd5651d3beb33ba7fdf0cd619c5edda12625e6ea982eca
7
+ data.tar.gz: 7472c8d1a662ced9691399abdd481a5a007a1bba8e94bfa142ed9f7107bc3b9628d4d48e457547ef9795ffd8b483013f90f5557a90b4badf7fef33fc81bd50d1
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_runtime_dependency 'clearwater'
20
+ spec.add_runtime_dependency 'clearwater', '~> 1.0.0.rc1'
21
21
  spec.add_runtime_dependency 'listen'
22
22
  spec.add_runtime_dependency 'faye-websocket'
23
23
 
@@ -31,14 +31,14 @@ module Clearwater
31
31
  begin
32
32
  puts "[Clearwater::HotLoader] Compiling #{filename}..."
33
33
  code = server.compile_file(filename)
34
- puts "[Clearwater::HotLoader] Hot-loading #{filename}..."
35
-
36
- sockets.each do |ws|
37
- ws.send code
38
- end
39
- rescue => e
34
+ rescue SyntaxError => e
40
35
  puts "ONOES! #{e.class} - #{e.message}"
41
36
  end
37
+
38
+ puts "[Clearwater::HotLoader] Hot-loading #{filename}..."
39
+ sockets.each do |ws|
40
+ ws.send code
41
+ end
42
42
  end
43
43
  }
44
44
  @listeners.each(&:start)
@@ -7,9 +7,7 @@ module Clearwater
7
7
  candidate_directories = Dir[
8
8
  *%w(
9
9
  app/assets/javascripts
10
- app/assets/javascripts/**/*
11
- assets
12
- assets/**/*
10
+ assets/js
13
11
  )
14
12
  ]
15
13
  self.directories = candidate_directories
@@ -7,7 +7,7 @@ module Clearwater
7
7
  @directory = directory
8
8
 
9
9
  @listener = Listen.to(directory) do |modified, added, removed|
10
- (modified + added).each do |file|
10
+ (modified + added).uniq.each do |file|
11
11
  block.call(file)
12
12
  end
13
13
  end
@@ -16,12 +16,14 @@ module Clearwater
16
16
  if WebSocket.websocket? env
17
17
  ws = WebSocket.new(env)
18
18
 
19
+ ws.on :open do
20
+ hot_loader.add_socket ws
21
+ end
22
+
19
23
  ws.on :close do
20
24
  hot_loader.remove_socket ws
21
25
  end
22
26
 
23
- hot_loader.add_socket ws
24
-
25
27
  ws.rack_response
26
28
  else
27
29
  [200, { 'Content-Type' => 'text/plain' }, ['Websockets only, please.']]
@@ -1,5 +1,5 @@
1
1
  module Clearwater
2
2
  module HotLoader
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -13,23 +13,78 @@ module Clearwater
13
13
  def initialize port, path='/clearwater_hot_loader'
14
14
  @port = port
15
15
  @path = path
16
+ Bowser.window.animation_frame do
17
+ div = Bowser.document.create_element('div')
18
+ Bowser.document.body.append div
19
+ @app = Clearwater::Application.new(
20
+ component: ConnectionIndicator.new(self),
21
+ element: div,
22
+ )
23
+ @app.call
24
+ end
16
25
  end
17
26
 
18
27
  def connect
19
28
  @socket = Bowser::WebSocket.new("ws://localhost:#{port}#{path}")
20
29
 
30
+ @socket.on :open do
31
+ @app.render
32
+ end
33
+
21
34
  @socket.on :message do |msg|
22
- %x{ eval(msg.native.data) }
35
+ begin
36
+ %x{ eval(msg.native.data) }
37
+ rescue => e
38
+ error_message = "[Clearwater::HotLoader] Error #{e.class}: #{e.message}"
39
+ `console.error(error_message)`
40
+ end
23
41
  Clearwater::Application.render
24
42
  end
25
43
 
26
44
  @socket.on :close do
27
- Bowser.window.delay 1 do
45
+ @app.render
46
+ Bowser.window.delay 0.5 do
28
47
  connect
29
48
  end
30
49
  end
31
50
 
32
51
  self
33
52
  end
53
+
54
+ def connected?
55
+ @socket.connected?
56
+ end
57
+
58
+ class ConnectionIndicator
59
+ include Clearwater::Component
60
+
61
+ def initialize loader
62
+ @loader = loader
63
+ end
64
+
65
+ def render
66
+ div({ style: style }, [
67
+ connection_status,
68
+ ])
69
+ end
70
+
71
+ def connection_status
72
+ span([
73
+ "Hot Loader: ",
74
+ @loader.connected? ? 'Connected' : 'Disconnected',
75
+ ])
76
+ end
77
+
78
+ def style
79
+ connected = @loader.connected?
80
+ {
81
+ position: :fixed,
82
+ bottom: 0,
83
+ right: 0,
84
+ background_color: connected ? :green : :red,
85
+ color: :white,
86
+ }
87
+ end
88
+ end
34
89
  end
35
90
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearwater-hot_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clearwater
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.0.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.0.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: listen
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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.5.1
139
+ rubygems_version: 2.6.11
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Reload your Clearwater app without refreshing the browser