react_on_rails 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +2 -0
  3. data/.eslintrc +33 -2
  4. data/.jscsrc +23 -4
  5. data/.rubocop.yml +1 -1
  6. data/README.md +8 -2
  7. data/app/assets/javascripts/react_on_rails.js +114 -70
  8. data/app/helpers/react_on_rails_helper.rb +79 -34
  9. data/docs/additional_reading/{generated_client_code.md → react-and-redux.md} +2 -1
  10. data/docs/additional_reading/react_router.md +35 -0
  11. data/docs/coding-style/linters.md +64 -0
  12. data/docs/coding-style/style.md +42 -0
  13. data/docs/contributing.md +12 -40
  14. data/docs/generator_testing_script.md +0 -1
  15. data/docs/install_and_releasing.md +24 -0
  16. data/docs/sample_generated_js/README.md +4 -0
  17. data/docs/sample_generated_js/server-generated.js +23 -9
  18. data/lib/generators/react_on_rails/base_generator.rb +12 -7
  19. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt +9 -0
  20. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +0 -7
  21. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt +2 -2
  22. data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +4 -1
  23. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintrc +34 -3
  24. data/lib/generators/react_on_rails/templates/js_linters/client/.jscsrc +15 -4
  25. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +1 -1
  26. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +1 -1
  27. data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +0 -1
  28. data/lib/react_on_rails/configuration.rb +4 -2
  29. data/lib/react_on_rails/prerender_error.rb +31 -0
  30. data/lib/react_on_rails/server_rendering_pool.rb +9 -18
  31. data/lib/react_on_rails/version.rb +1 -1
  32. metadata +9 -3
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "preset": "airbnb",
3
- "fileExtensions": [".js", ".jsx"],
4
- "excludeFiles": ["build/**", "node_modules/**"],
5
-
6
- "validateQuoteMarks": null // Issue with JSX quotemarks: https://github.com/jscs-dev/babel-jscs/issues/12
3
+ "fileExtensions": [
4
+ ".js",
5
+ ".jsx"
6
+ ],
7
+ "excludeFiles": [
8
+ "assets/**",
9
+ "build/**",
10
+ "node_modules/**"
11
+ ],
12
+ "esprima": "babel-jscs",
13
+ "validateQuoteMarks": {
14
+ "mark": "'",
15
+ "escape": true,
16
+ "ignoreJSX": true
17
+ }
7
18
  }
@@ -31,7 +31,7 @@ export default class HelloWorldWidget extends React.Component {
31
31
  </h3>
32
32
  <p>
33
33
  Say hello to:
34
- <input type="text" ref="name" value={this.props.name} onChange={this._handleChange} />
34
+ <input type="text" value={this.props.name} onChange={this._handleChange} />
35
35
  </p>
36
36
  </div>
37
37
  );
@@ -1,6 +1,6 @@
1
1
  // This file is our manifest of all reducers for the app.
2
2
  // See also /client/app/bundles/HelloWorld/store/helloWorldStore.jsx
3
- // A real world app will like have many reducers and it helps to organize them in one file.
3
+ // A real world app will likely have many reducers and it helps to organize them in one file.
4
4
  // `https://github.com/shakacode/react_on_rails/tree/master/docs/additional_reading/generated_client_code.md`
5
5
  import helloWorldReducer from './helloWorldReducer';
6
6
  import { $$initialState as $$helloWorldState } from './helloWorldReducer';
@@ -1,5 +1,4 @@
1
1
  /* eslint no-console: 0 */
2
- import _ from 'lodash';
3
2
 
4
3
  // This logger should be configured not to run in a production environment.
5
4
  // See https://github.com/petehunt/webpack-howto#6-feature-flags for you might turn this off for production.
@@ -10,6 +10,7 @@ module ReactOnRails
10
10
  replay_console: true,
11
11
  logging_on_server: true,
12
12
  generator_function: false,
13
+ raise_on_prerender_error: false,
13
14
  trace: Rails.env.development?,
14
15
  development_mode: Rails.env.development?,
15
16
  server_renderer_pool_size: 1,
@@ -20,12 +21,12 @@ module ReactOnRails
20
21
  attr_accessor :server_bundle_js_file, :prerender, :replay_console,
21
22
  :generator_function, :trace, :development_mode,
22
23
  :logging_on_server, :server_renderer_pool_size,
23
- :server_renderer_timeout
24
+ :server_renderer_timeout, :raise_on_prerender_error
24
25
 
25
26
  def initialize(server_bundle_js_file: nil, prerender: nil, replay_console: nil,
26
27
  generator_function: nil, trace: nil, development_mode: nil,
27
28
  logging_on_server: nil, server_renderer_pool_size: nil,
28
- server_renderer_timeout: nil)
29
+ server_renderer_timeout: nil, raise_on_prerender_error: nil)
29
30
  if File.exist?(server_bundle_js_file)
30
31
  self.server_bundle_js_file = server_bundle_js_file
31
32
  else
@@ -42,6 +43,7 @@ module ReactOnRails
42
43
  self.development_mode = development_mode
43
44
  end
44
45
  self.trace = trace.nil? ? Rails.env.development? : trace
46
+ self.raise_on_prerender_error = raise_on_prerender_error
45
47
 
46
48
  # Server rendering:
47
49
  self.server_renderer_pool_size = self.development_mode ? 1 : server_renderer_pool_size
@@ -0,0 +1,31 @@
1
+ module ReactOnRails
2
+ class PrerenderError < RuntimeError
3
+ # err might be nil if JS caught the error
4
+ def initialize(component_name: nil, err: nil, props: nil,
5
+ js_code: nil, console_messages: nil)
6
+ message = "ERROR in SERVER PRERENDERING\n"
7
+ if err
8
+ message << <<-MSG
9
+ Encountered error: \"#{err}\"
10
+ MSG
11
+ backtrace = err.backtrace.join("\n")
12
+ else
13
+ backtrace = nil
14
+ end
15
+ message << <<-MSG
16
+ when prerendering #{component_name} with props: #{props}
17
+ js_code was:
18
+ #{js_code}
19
+ MSG
20
+
21
+ if console_messages
22
+ message << <<-MSG
23
+ console messages:
24
+ #{console_messages}
25
+ MSG
26
+ end
27
+
28
+ super([message, backtrace].compact.join("\n"))
29
+ end
30
+ end
31
+ end
@@ -14,36 +14,27 @@ module ReactOnRails
14
14
  def self.reset_pool_if_server_bundle_was_modified
15
15
  return unless ReactOnRails.configuration.development_mode
16
16
  file_mtime = File.mtime(ReactOnRails.configuration.server_bundle_js_file)
17
- first_time = @server_bundle_timestamp.nil?
18
- return if first_time || @server_bundle_timestamp == file_mtime
17
+ @server_bundle_timestamp ||= file_mtime
18
+ return if @server_bundle_timestamp == file_mtime
19
19
  ReactOnRails::ServerRenderingPool.reset_pool
20
20
  @server_bundle_timestamp = file_mtime
21
21
  end
22
22
 
23
- class PrerenderError < RuntimeError
24
- def initialize(component_name, props, js_message)
25
- message = ["Encountered error \"#{js_message}\" when prerendering #{component_name} with #{props}",
26
- js_message.backtrace.join("\n")].join("\n")
27
- super(message)
28
- end
29
- end
30
-
31
23
  # js_code: JavaScript expression that returns a string.
32
- # Returns an Array:
33
- # [0]: string of HTML for direct insertion on the page by evaluating js_code
34
- # [1]: console messages
35
- # Note, js_code does not have to be based on React.
36
- # js_code MUST RETURN json stringify array of two elements
24
+ # Returns a Hash:
25
+ # html: string of HTML for direct insertion on the page by evaluating js_code
26
+ # consoleReplayScript: script for replaying console
27
+ # hasErrors: true if server rendering errors
28
+ # Note, js_code does not have to be based on React.
29
+ # js_code MUST RETURN json stringify Object
37
30
  # Calling code will probably call 'html_safe' on return value before rendering to the view.
38
31
  def self.server_render_js_with_console_logging(js_code)
39
32
  trace_messsage(js_code)
40
-
41
33
  json_string = eval_js(js_code)
42
- # element 0 is the html, element 1 is the script tag for the server console output
43
34
  result = JSON.parse(json_string)
44
35
 
45
36
  if ReactOnRails.configuration.logging_on_server
46
- console_script = result[1]
37
+ console_script = result["consoleReplayScript"]
47
38
  console_script_lines = console_script.split("\n")
48
39
  console_script_lines = console_script_lines[2..-2]
49
40
  re = /console\.log\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
@@ -1,3 +1,3 @@
1
1
  module ReactOnRails
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -149,16 +149,21 @@ files:
149
149
  - app/helpers/react_on_rails_helper.rb
150
150
  - docker-compose.yml
151
151
  - docs/LICENSE
152
- - docs/additional_reading/generated_client_code.md
153
152
  - docs/additional_reading/heroku_deployment.md
154
153
  - docs/additional_reading/manual_installation.md
155
154
  - docs/additional_reading/node_dependencies_and_npm.md
156
155
  - docs/additional_reading/optional_configuration.md
156
+ - docs/additional_reading/react-and-redux.md
157
+ - docs/additional_reading/react_router.md
157
158
  - docs/additional_reading/server_rendering_tips.md
158
159
  - docs/additional_reading/tips.md
159
160
  - docs/code_of_conduct.md
161
+ - docs/coding-style/linters.md
162
+ - docs/coding-style/style.md
160
163
  - docs/contributing.md
161
164
  - docs/generator_testing_script.md
165
+ - docs/install_and_releasing.md
166
+ - docs/sample_generated_js/README.md
162
167
  - docs/sample_generated_js/client-generated.js
163
168
  - docs/sample_generated_js/server-generated.js
164
169
  - lib/generators/react_on_rails/base_generator.rb
@@ -224,6 +229,7 @@ files:
224
229
  - lib/react_on_rails.rb
225
230
  - lib/react_on_rails/configuration.rb
226
231
  - lib/react_on_rails/engine.rb
232
+ - lib/react_on_rails/prerender_error.rb
227
233
  - lib/react_on_rails/server_rendering_pool.rb
228
234
  - lib/react_on_rails/version.rb
229
235
  - react_on_rails.gemspec