opal_hot_reloader 0.1.3 → 0.1.4
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 +24 -0
- data/lib/opal_hot_reloader/version.rb +1 -1
- data/opal/opal_hot_reloader.rb +48 -29
- data/spec-opal/opal_hot_reloader_spec.rb +10 -0
- 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: a867c114bf9d71275cc023f35c644944abe5decc
|
4
|
+
data.tar.gz: 4d0c10c661b6180a2881e5d6fbac3a10d6b77e02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 267a9d178686be33693532036a2bd8919f2f15e362f6ab20df3f293c60070eee5b9988dfeb8097519077aafcb7a2f3cf523a1f6e20390d0b55e08478780f2ff3
|
7
|
+
data.tar.gz: 637125fea8cf8526c70c7e84badc5b5587243d3fec496fc9aef8d45c96c530e883d54001e396005b418adea48143ea5e2beea114e66c74213f9d99186cb872e1
|
data/Changelog.org
CHANGED
data/README.md
CHANGED
@@ -70,10 +70,34 @@ If you are using the default port then you can just call:
|
|
70
70
|
OpalHotReloader.listen
|
71
71
|
```
|
72
72
|
|
73
|
+
#### Alerts
|
74
|
+
|
75
|
+
![Reload Error Alert](images/reload_error.png)
|
76
|
+
By default, if there is an error hot loading code, opal_hot_reloader
|
77
|
+
will present an alert of the error. The following options can be used
|
78
|
+
to turn the alerts on and off:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
OpalHotReloader.alerts_on! # turns on alerts
|
82
|
+
OpalHotReloader.alerts_off! # turns off alerts
|
83
|
+
|
84
|
+
```
|
85
|
+
|
86
|
+
|
73
87
|
This will open up a websocket from the client to the server on the given port. The server-side should already be running.
|
74
88
|
|
75
89
|
Enjoy!
|
76
90
|
|
91
|
+
#### Run only in development on Rails
|
92
|
+
One way to run this only in development on Rails is to change your application.js.rb to application.js.rb.erb and add this to the bottom of the file
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
<% if Rails.env.development? %>
|
96
|
+
require 'opal_hot_reloader'
|
97
|
+
OpalHotReloader.listen
|
98
|
+
<% end %>
|
99
|
+
```
|
100
|
+
|
77
101
|
## Vision
|
78
102
|
|
79
103
|
Some of you might be asking? Why do this, isn't this reinventing the
|
data/opal/opal_hot_reloader.rb
CHANGED
@@ -20,6 +20,25 @@ class OpalHotReloader
|
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
|
+
def notify_error(reload_request)
|
24
|
+
msg = "OpalHotReloader #{reload_request[:filename]} RELOAD ERROR:\n\n#{$!}"
|
25
|
+
puts msg
|
26
|
+
alert msg if use_alert?
|
27
|
+
end
|
28
|
+
|
29
|
+
@@USE_ALERT = true
|
30
|
+
def self.alerts_on!
|
31
|
+
@@USE_ALERT = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.alerts_off!
|
35
|
+
@@USE_ALERT = false
|
36
|
+
end
|
37
|
+
|
38
|
+
def use_alert?
|
39
|
+
@@USE_ALERT
|
40
|
+
end
|
41
|
+
|
23
42
|
def reload(e)
|
24
43
|
reload_request = JSON.parse(`e.data`)
|
25
44
|
if reload_request[:type] == "ruby"
|
@@ -27,7 +46,7 @@ class OpalHotReloader
|
|
27
46
|
begin
|
28
47
|
$eval_proc.call reload_request[:source_code]
|
29
48
|
rescue
|
30
|
-
|
49
|
+
notify_error(reload_request)
|
31
50
|
end
|
32
51
|
if @reload_post_callback
|
33
52
|
@reload_post_callback.call
|
@@ -42,37 +61,37 @@ class OpalHotReloader
|
|
42
61
|
|
43
62
|
# @param port [Integer] opal hot reloader port to connect to
|
44
63
|
# @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!
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
64
|
+
def initialize(port=25222, &reload_post_callback)
|
65
|
+
@port = port
|
66
|
+
@reload_post_callback = reload_post_callback
|
67
|
+
@css_reloader = CssReloader.new
|
68
|
+
end
|
69
|
+
# Opens a websocket connection that evaluates new files and runs the optional @reload_post_callback
|
70
|
+
def listen
|
71
|
+
connect_to_websocket(@port)
|
72
|
+
end
|
54
73
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
create_framework_aware_server(port)
|
74
|
+
# convenience method to start a listen w/one line
|
75
|
+
# @param port [Integer] opal hot reloader port to connect to. Defaults to 25222 to match opal-hot-loader default
|
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)
|
78
|
+
return if @server
|
79
|
+
if reactrb
|
80
|
+
warn "OpalHotReloader.listen(#{port}): reactrb flag is deprectated and will be removed in gem release 0.2. React will automatically be detected"
|
64
81
|
end
|
65
|
-
|
82
|
+
create_framework_aware_server(port)
|
83
|
+
end
|
84
|
+
# Automatically add in framework specific hooks
|
66
85
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
@server.listen
|
86
|
+
def self.create_framework_aware_server(port)
|
87
|
+
if defined? ::React
|
88
|
+
ReactrbPatches.patch!
|
89
|
+
@server = OpalHotReloader.new(port) { React::Component.force_update! }
|
90
|
+
else
|
91
|
+
puts "No framework detected"
|
92
|
+
@server = OpalHotReloader.new(port)
|
76
93
|
end
|
94
|
+
@server.listen
|
95
|
+
end
|
77
96
|
|
78
97
|
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.4
|
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-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- opal/opal_hot_reloader/socket.rb
|
126
126
|
- opal_hot_reloader.gemspec
|
127
127
|
- spec-opal/opal_hot_reloader/css_reloader_spec.rb
|
128
|
+
- spec-opal/opal_hot_reloader_spec.rb
|
128
129
|
homepage: https://github.com/fkchang/opal-hot-reloader
|
129
130
|
licenses:
|
130
131
|
- MIT
|