react-rails-hot-loader 0.3.0 → 0.4.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: 6e83238b5557bc6c6decdb17fd085f2de6417ea7
4
- data.tar.gz: cd502ba5a6f1628240806b4e87e2d9e6c6053769
3
+ metadata.gz: a8f8205a8fecc4ea01e396791be7634c7ccc10d3
4
+ data.tar.gz: 0f4723d12e64e9b90a3d661fb4790aad53541353
5
5
  SHA512:
6
- metadata.gz: 37f574e95527201e7a5ba90ec339867c6e925d6678d3c45eb80f341ba34dcec1240ce7f8b1b3b30d7d761ce3ab0d270acbe7861c112070fdee3e1eed5c7ed5e8
7
- data.tar.gz: c7b8887ae4e57aa06e00be047b413630ebb7572362d3b3678af33bc70e358a88ce96c05f4a817f1a7ed9e438b2fd1c1628b32ef619af8774a043e722e51b715c
6
+ metadata.gz: ca06352fe32da0f8bb4bd276768a30840d1fc0639f3041262063a7edfd35cf09d91dc2769808643205ec853e43cb926743537fecb45ddf2df444619866eb8cc7
7
+ data.tar.gz: 9e163bd9b45976a684f438a8674c303602f6cbffae2140b7729560cdaa1d88fbed9d3f7c176fa386c6c1a43e6b10f9a77bc13f37d61e1a1ae19d4dca8fa2bd14
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # React::Rails::HotLoader
1
+ # React::Rails::HotLoader
2
2
 
3
3
  Reload React.js components with Ruby on Rails & [`react-rails`](http://github.com/reactjs/react-rails).
4
4
 
5
5
  When you edit components, they'll be reloaded by the browser & re-mounted in the page.
6
6
 
7
- [![Gem Version](https://badge.fury.io/rb/react-rails-hot-loader.svg)](http://badge.fury.io/rb/react-rails-hot-loader) [![Build Status](https://travis-ci.org/rmosolgo/react-rails-hot-loader.svg)](https://travis-ci.org/rmosolgo/react-rails-hot-loader) [![Code Climate](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader/badges/gpa.svg)](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader) [![Test Coverage](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader/badges/coverage.svg)](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader/coverage)
7
+ [![Gem Version](https://badge.fury.io/rb/react-rails-hot-loader.svg)](http://badge.fury.io/rb/react-rails-hot-loader) [![Build Status](https://travis-ci.org/rmosolgo/react-rails-hot-loader.svg)](https://travis-ci.org/rmosolgo/react-rails-hot-loader) [![Code Climate](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader/badges/gpa.svg)](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader) [![Test Coverage](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader/badges/coverage.svg)](https://codeclimate.com/github/rmosolgo/react-rails-hot-loader/coverage)
8
8
 
9
9
  ## Installation
10
10
 
@@ -46,12 +46,21 @@ Or install it yourself as:
46
46
 
47
47
  - Edit files in `/app/assets/javascripts` & save changes -- they'll be reloaded in the client and React components will be remounted.
48
48
 
49
+ ## Configuration
50
+
51
+ If you notice that your assets are not being recompiled and hot loaded, it could be because they aren't being matched by the default asset glob used (`**/*.{js,coffee}*`). You can modify this asset glob like so:
52
+
53
+ ```ruby
54
+ # app/config/initializers/react_rails_hot_loader.rb
55
+ React::Rails::HotLoader::AssetChangeSet.asset_glob = "**/*.{js,rb}*" # I <3 Opal
56
+ ```
57
+
49
58
  ## Doeses & Doesn'ts
50
59
 
51
60
  `react-rails-hot-loader` ...
52
61
 
53
62
  - __does__ set up a WebSocket server & client
54
- - __does__ reload JS assets when they change (from `/app/assets/javascripts/*.js*`)
63
+ - __does__ reload JS assets when they change (from `/app/assets/javascripts/*.{js,coffee}*`)
55
64
  - __does__ remount components (via `ReactRailsUJS`) after reloading assets
56
65
  - __does__ preserve state & props (because `React.render` does that out of the box)
57
66
  - __doesn't__ reload Rails view files (`html`, `erb`, `slim`, etc)
@@ -59,9 +68,9 @@ Or install it yourself as:
59
68
 
60
69
  ## TODO
61
70
 
62
- - Handle Passenger occasionally killing background threads :(
63
- - Replace pinging with file watching
71
+ - Replace pinging with file watching?
64
72
  - Add `rails g react-rails-hot-loader:install` to add initializer and JS
73
+ - Remove need for initializer by automatically starting in `config.after_initialize`?
65
74
 
66
75
  ## License
67
76
 
@@ -3,12 +3,15 @@ module React
3
3
  module HotLoader
4
4
  class AssetChangeSet
5
5
  attr_reader :since, :path, :changed_files, :changed_file_names, :changed_asset_contents
6
+ class_attribute :asset_glob
7
+ self.asset_glob = "/**/*.{js,coffee}*"
8
+
6
9
  # initialize with a path and time
7
10
  # to find files which changed since that time
8
11
  def initialize(since:, path: ::Rails.root.join("app/assets/javascripts"))
9
12
  @since = since
10
13
  @path = path.to_s
11
- asset_glob = path.to_s + "/**/*.js*"
14
+ asset_glob = File.join(path, AssetChangeSet.asset_glob)
12
15
  @changed_files = Dir.glob(asset_glob).select { |f| File.mtime(f) >= since }
13
16
  @changed_file_names = changed_files.map { |f| f.split("/").last }
14
17
  @changed_asset_contents = changed_files.map do |f|
@@ -9,6 +9,9 @@ module React
9
9
 
10
10
  config.after_initialize do |app|
11
11
  ActionDispatch::Reloader.to_prepare do
12
+ # Seems like Passenger kills threads on the main process
13
+ # In that case, `starting_worker_process` isn't good enough
14
+ # because it doesn't run :(
12
15
  React::Rails::HotLoader.restart
13
16
  end
14
17
 
@@ -21,23 +21,15 @@ module React
21
21
 
22
22
  private
23
23
 
24
- def start
25
- @server_thread = Thread.new do
26
- begin
27
- serve
28
- rescue StandardError => err
29
- React::Rails::HotLoader.error(err)
30
- end
31
- end
32
- end
33
-
34
24
  # If the Rails server runs event machine already,
35
25
  # don't run EventMachine again, instead hook in with `next_tick`
36
- def serve
26
+ def start
37
27
  if already_has_event_machine_server?
38
28
  EM.next_tick { run_websocket_server }
39
29
  else
40
- EM.run { run_websocket_server }
30
+ Thread.new do
31
+ EM.run { run_websocket_server }
32
+ end
41
33
  end
42
34
  end
43
35
 
@@ -55,15 +47,22 @@ module React
55
47
  end
56
48
 
57
49
  def run_websocket_server
58
- React::Rails::HotLoader.log("starting WS server: ws://#{host}:#{port}")
50
+ ws_url = "ws://#{host}:#{port}"
51
+ React::Rails::HotLoader.log("starting WS server (#{ws_url})")
59
52
 
60
53
  EM::WebSocket.run(host: host, port: port) do |ws|
61
- ws.onopen { React::Rails::HotLoader.log("opened a connection") }
54
+ ws.onopen { React::Rails::HotLoader.log("opened a connection (#{ws_url})") }
62
55
  ws.onmessage { |msg| handle_message(ws, msg) }
63
- ws.onclose { React::Rails::HotLoader.log("closed a connection") }
56
+ ws.onclose { React::Rails::HotLoader.log("closed a connection (#{ws_url})") }
64
57
  end
65
58
 
66
- React::Rails::HotLoader.log("started WS server")
59
+ React::Rails::HotLoader.log("started WS server (#{ws_url})")
60
+ rescue StandardError => err
61
+ if err.message =~ /no acceptor/
62
+ React::Rails::HotLoader.log("WS server is already running (#{ws_url})")
63
+ else
64
+ React::Rails::HotLoader.error(err)
65
+ end
67
66
  end
68
67
 
69
68
  def already_has_event_machine_server?
@@ -1,7 +1,7 @@
1
1
  module React
2
2
  module Rails
3
3
  module HotLoader
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
6
6
  end
7
7
  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.3.0
4
+ version: 0.4.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-08-10 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket