reactrb 0.8.8 → 0.9.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.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +24 -3
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +1154 -3
  5. data/.travis.yml +20 -0
  6. data/Appraisals +20 -0
  7. data/CHANGELOG.md +28 -3
  8. data/Gemfile +4 -5
  9. data/README.md +6 -9
  10. data/Rakefile +6 -1
  11. data/config.ru +7 -6
  12. data/gemfiles/opal_0.8_react_13.gemfile +13 -0
  13. data/gemfiles/opal_0.8_react_14.gemfile +13 -0
  14. data/gemfiles/opal_0.8_react_15.gemfile +13 -0
  15. data/gemfiles/opal_0.9_react_13.gemfile +13 -0
  16. data/gemfiles/opal_0.9_react_14.gemfile +13 -0
  17. data/gemfiles/opal_0.9_react_15.gemfile +13 -0
  18. data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +1 -1
  19. data/lib/rails-helpers/top_level_rails_component.rb +1 -1
  20. data/lib/react-sources/react-server.js +2 -0
  21. data/lib/react/api.rb +13 -12
  22. data/lib/react/children.rb +30 -0
  23. data/lib/react/component.rb +27 -46
  24. data/lib/react/component/class_methods.rb +28 -32
  25. data/lib/react/component/dsl_instance_methods.rb +4 -34
  26. data/lib/react/component/params.rb +6 -0
  27. data/lib/react/component/props_wrapper.rb +22 -27
  28. data/lib/react/component/should_component_update.rb +98 -0
  29. data/lib/react/component/tags.rb +45 -4
  30. data/lib/react/element.rb +26 -13
  31. data/lib/react/object.rb +15 -0
  32. data/lib/react/react-source.rb +9 -0
  33. data/lib/react/rendering_context.rb +97 -93
  34. data/lib/react/state.rb +27 -21
  35. data/lib/react/test.rb +16 -0
  36. data/lib/react/test/dsl.rb +17 -0
  37. data/lib/react/test/matchers/render_html_matcher.rb +49 -0
  38. data/lib/react/test/rspec.rb +15 -0
  39. data/lib/react/test/session.rb +46 -0
  40. data/lib/react/top_level.rb +50 -14
  41. data/lib/react/validator.rb +5 -5
  42. data/lib/reactive-ruby/isomorphic_helpers.rb +0 -7
  43. data/lib/reactive-ruby/version.rb +1 -1
  44. data/lib/reactrb.rb +14 -14
  45. data/lib/reactrb/deep-compare.rb +24 -0
  46. data/lib/sources/react-latest.js +2 -0
  47. data/lib/sources/react-v13.js +4 -1
  48. data/lib/sources/react-v14.js +3 -84
  49. data/lib/sources/react-v15.js +3 -0
  50. data/logo1.png +0 -0
  51. data/logo2.png +0 -0
  52. data/logo3.png +0 -0
  53. data/path_release_steps.md +1 -1
  54. data/reactrb.gemspec +2 -3
  55. data/spec/react/children_spec.rb +76 -0
  56. data/spec/react/component/base_spec.rb +3 -7
  57. data/spec/react/component_spec.rb +181 -60
  58. data/spec/react/dsl_spec.rb +26 -19
  59. data/spec/react/element_spec.rb +16 -1
  60. data/spec/react/native_library_spec.rb +20 -0
  61. data/spec/react/opal_jquery_extensions_spec.rb +27 -0
  62. data/spec/react/param_declaration_spec.rb +47 -78
  63. data/spec/react/react_spec.rb +7 -9
  64. data/spec/react/state_spec.rb +29 -0
  65. data/spec/react/test/dsl_spec.rb +43 -0
  66. data/spec/react/test/matchers/render_html_matcher_spec.rb +83 -0
  67. data/spec/react/test/rspec_spec.rb +62 -0
  68. data/spec/react/test/session_spec.rb +100 -0
  69. data/spec/react/test/utils_spec.rb +45 -0
  70. data/spec/react/top_level_component_spec.rb +33 -5
  71. data/spec/react/tutorial/tutorial_spec.rb +5 -5
  72. data/spec/react/validator_spec.rb +10 -13
  73. data/spec/reactive-ruby/component_loader_spec.rb +3 -0
  74. data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +5 -4
  75. data/spec/spec_helper.rb +6 -3
  76. data/spec/support/react/spec_helpers.rb +9 -2
  77. metadata +47 -124
  78. data/example/examples/Gemfile +0 -7
  79. data/example/examples/app/basics.js.rb +0 -42
  80. data/example/examples/app/items.rb +0 -11
  81. data/example/examples/app/jquery.js +0 -5
  82. data/example/examples/app/nodes.rb +0 -61
  83. data/example/examples/app/react-router.js +0 -6
  84. data/example/examples/app/react_api_demo.rb +0 -29
  85. data/example/examples/app/rerendering.rb +0 -72
  86. data/example/examples/app/reuse.rb +0 -59
  87. data/example/examples/app/show.rb +0 -52
  88. data/example/examples/config.ru +0 -38
  89. data/example/rails-tutorial/.gitignore +0 -17
  90. data/example/rails-tutorial/Gemfile +0 -51
  91. data/example/rails-tutorial/README.rdoc +0 -28
  92. data/example/rails-tutorial/Rakefile +0 -6
  93. data/example/rails-tutorial/app/assets/images/.keep +0 -0
  94. data/example/rails-tutorial/app/assets/javascripts/application.rb +0 -15
  95. data/example/rails-tutorial/app/assets/stylesheets/application.css +0 -15
  96. data/example/rails-tutorial/app/controllers/application_controller.rb +0 -6
  97. data/example/rails-tutorial/app/controllers/concerns/.keep +0 -0
  98. data/example/rails-tutorial/app/controllers/home_controller.rb +0 -6
  99. data/example/rails-tutorial/app/helpers/application_helper.rb +0 -2
  100. data/example/rails-tutorial/app/mailers/.keep +0 -0
  101. data/example/rails-tutorial/app/models/.keep +0 -0
  102. data/example/rails-tutorial/app/models/concerns/.keep +0 -0
  103. data/example/rails-tutorial/app/views/components.rb +0 -3
  104. data/example/rails-tutorial/app/views/components/home/show.rb +0 -47
  105. data/example/rails-tutorial/app/views/layouts/application.html.erb +0 -14
  106. data/example/rails-tutorial/bin/bundle +0 -3
  107. data/example/rails-tutorial/bin/rails +0 -8
  108. data/example/rails-tutorial/bin/rake +0 -8
  109. data/example/rails-tutorial/bin/setup +0 -29
  110. data/example/rails-tutorial/bin/spring +0 -15
  111. data/example/rails-tutorial/config.ru +0 -4
  112. data/example/rails-tutorial/config/application.rb +0 -26
  113. data/example/rails-tutorial/config/boot.rb +0 -3
  114. data/example/rails-tutorial/config/database.yml +0 -25
  115. data/example/rails-tutorial/config/environment.rb +0 -5
  116. data/example/rails-tutorial/config/environments/development.rb +0 -41
  117. data/example/rails-tutorial/config/environments/production.rb +0 -79
  118. data/example/rails-tutorial/config/environments/test.rb +0 -42
  119. data/example/rails-tutorial/config/initializers/assets.rb +0 -11
  120. data/example/rails-tutorial/config/initializers/backtrace_silencers.rb +0 -7
  121. data/example/rails-tutorial/config/initializers/cookies_serializer.rb +0 -3
  122. data/example/rails-tutorial/config/initializers/filter_parameter_logging.rb +0 -4
  123. data/example/rails-tutorial/config/initializers/inflections.rb +0 -16
  124. data/example/rails-tutorial/config/initializers/mime_types.rb +0 -4
  125. data/example/rails-tutorial/config/initializers/session_store.rb +0 -3
  126. data/example/rails-tutorial/config/initializers/wrap_parameters.rb +0 -14
  127. data/example/rails-tutorial/config/locales/en.yml +0 -23
  128. data/example/rails-tutorial/config/routes.rb +0 -59
  129. data/example/rails-tutorial/config/secrets.yml +0 -22
  130. data/example/rails-tutorial/db/seeds.rb +0 -7
  131. data/example/rails-tutorial/lib/assets/.keep +0 -0
  132. data/example/rails-tutorial/lib/tasks/.keep +0 -0
  133. data/example/rails-tutorial/log/.keep +0 -0
  134. data/example/rails-tutorial/public/404.html +0 -67
  135. data/example/rails-tutorial/public/422.html +0 -67
  136. data/example/rails-tutorial/public/500.html +0 -66
  137. data/example/rails-tutorial/public/favicon.ico +0 -0
  138. data/example/rails-tutorial/public/robots.txt +0 -5
  139. data/example/rails-tutorial/test/controllers/.keep +0 -0
  140. data/example/rails-tutorial/test/fixtures/.keep +0 -0
  141. data/example/rails-tutorial/test/helpers/.keep +0 -0
  142. data/example/rails-tutorial/test/integration/.keep +0 -0
  143. data/example/rails-tutorial/test/mailers/.keep +0 -0
  144. data/example/rails-tutorial/test/models/.keep +0 -0
  145. data/example/rails-tutorial/test/test_helper.rb +0 -10
  146. data/example/rails-tutorial/vendor/assets/javascripts/.keep +0 -0
  147. data/example/rails-tutorial/vendor/assets/stylesheets/.keep +0 -0
  148. data/example/sinatra-tutorial/.DS_Store +0 -0
  149. data/example/sinatra-tutorial/Gemfile +0 -5
  150. data/example/sinatra-tutorial/README.md +0 -8
  151. data/example/sinatra-tutorial/_comments.json +0 -42
  152. data/example/sinatra-tutorial/app/example.rb +0 -290
  153. data/example/sinatra-tutorial/app/jquery.js +0 -5
  154. data/example/sinatra-tutorial/config.ru +0 -58
  155. data/example/sinatra-tutorial/public/base.css +0 -62
  156. data/example/todos/Gemfile +0 -11
  157. data/example/todos/README.md +0 -37
  158. data/example/todos/Rakefile +0 -8
  159. data/example/todos/app/application.rb +0 -22
  160. data/example/todos/app/components/app.react.rb +0 -61
  161. data/example/todos/app/components/footer.react.rb +0 -31
  162. data/example/todos/app/components/todo_item.react.rb +0 -46
  163. data/example/todos/app/components/todo_list.react.rb +0 -25
  164. data/example/todos/app/models/todo.rb +0 -19
  165. data/example/todos/config.ru +0 -14
  166. data/example/todos/index.html.haml +0 -16
  167. data/example/todos/spec/todo_spec.rb +0 -28
  168. data/example/todos/vendor/base.css +0 -410
  169. data/example/todos/vendor/bg.png +0 -0
  170. data/example/todos/vendor/jquery.js +0 -4
@@ -4,6 +4,26 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1
6
6
  - jruby-19mode
7
+ before_script:
8
+ - phantomjs --version
7
9
  script:
8
10
  - bundle exec rake test_app
9
11
  - bundle exec rake
12
+ gemfile:
13
+ - gemfiles/opal_0.8_react_13.gemfile
14
+ - gemfiles/opal_0.8_react_14.gemfile
15
+ - gemfiles/opal_0.8_react_15.gemfile
16
+ - gemfiles/opal_0.9_react_13.gemfile
17
+ - gemfiles/opal_0.9_react_14.gemfile
18
+ - gemfiles/opal_0.9_react_15.gemfile
19
+
20
+ # These two setup seems to run indefinitely long
21
+ # further investigation required.
22
+ matrix:
23
+ exclude:
24
+ - rvm: jruby-19mode
25
+ gemfile: gemfiles/opal_0.9_react_13.gemfile
26
+ - rvm: jruby-19mode
27
+ gemfile: gemfiles/opal_0.9_react_14.gemfile
28
+ - rvm: jruby-19mode
29
+ gemfile: gemfiles/opal_0.9_react_15.gemfile
@@ -0,0 +1,20 @@
1
+ opal_versions = ['0.8', '0.9']
2
+ react_versions_map = {
3
+ '13' => '~> 1.3.3',
4
+ '14' => '~> 1.6.2',
5
+ '15' => '~> 1.8.2'
6
+ }
7
+ opal_rails_versions_map = {
8
+ '0.8' => '~> 0.8.1',
9
+ '0.9' => '~> 0.9.0',
10
+ }
11
+
12
+ opal_versions.each do |opal_v|
13
+ react_versions_map.each do |react_v, react_rails_v|
14
+ appraise "opal-#{opal_v}-react-#{react_v}" do
15
+ gem 'opal', "~> #{opal_v}.0"
16
+ gem 'opal-rails', opal_rails_versions_map[opal_v]
17
+ gem 'react-rails', react_rails_v, require: false
18
+ end
19
+ end
20
+ end
@@ -18,12 +18,37 @@ Whitespace conventions:
18
18
  - 1 spaces before normal text
19
19
  -->
20
20
 
21
+ ## [0.9.0] - Unreleased
22
+
23
+ ### Added
24
+
25
+ - `react/react-source` is the suggested way to include ReactJS sources now. Simply require `react/react-source` immediately before the `require "reactrb"` in your Opal code will make it work.
26
+
27
+ ### Deprecated
28
+
29
+ - `react-latest` & `react-v1x` is deprecated. Use `react/react-source` instead.
30
+
31
+ ### Removed
32
+
33
+ - `opal-browser` is removed from runtime dependency. (#133)
34
+
35
+ ### Fixed
36
+
37
+ - `$window#on` in `opal-jquery` is broken. (#166)
38
+ - `Element#render` trigger unnecessary re-mounts when called multiple times. (#170)
39
+ - Gets rid of react warnings about updating state during render (#155)
40
+ - Multiple HAML classes (i.e. div.foo.bar) was not working (regression introduced in 0.8.8)
41
+ - Don't send nil (null) to form components as the value string (#157)
42
+ - Process `params` (props) correctly when using `Element#on` or `Element#render` (#158)
43
+ - Deprecate shallow param compare (#156)
44
+
45
+
21
46
  ## [0.8.8] - 2016-07-13
22
47
 
23
48
  ### Added
24
49
 
25
50
  - More helpful error messages on render failures (#152)
26
- - `Element#on('<my_event_name>')` subscribes `my_event_name` (#153)
51
+ - `Element#on('<my_event_name>')` subscribes to `my_event_name` (#153)
27
52
 
28
53
  ### Changed
29
54
 
@@ -31,12 +56,12 @@ Whitespace conventions:
31
56
 
32
57
  ### Deprecated
33
58
 
34
- - `Element#(:event)` subscription to `_onEvent` is deprecated. Once you have changed params named `_on...` to `on_...` you can `require 'reactrb/new-event-name-convention.rb'` to avoid spurious react warning messages. (#153)
59
+ - `Element#on(:event)` subscription to `_onEvent` is deprecated. Once you have changed params named `_on...` to `on_...` you can `require 'reactrb/new-event-name-convention.rb'` to avoid spurious react warning messages. (#153)
35
60
 
36
61
 
37
62
  ### Fixed
38
63
 
39
- - when using the Element['#container'].render... method generates spurious react error (#154)
64
+ - The `Element['#container'].render...` method generates a spurious react error (#154)
40
65
 
41
66
 
42
67
 
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
- #gem 'opal-rails', git: "https://github.com/opal/opal-rails.git"
3
- #gem 'opal', "~> 0.9.x"
4
- #gem 'opal-rails', git: "https://github.com/reactrb/opal-rails.git"
5
- #gem 'opal-rspec-rails', git: 'https://github.com/reactrb/opal-rspec-rails.git'
6
- gem 'pry'
7
2
  gemspec
3
+
4
+ group :development do
5
+ gem "appraisal"
6
+ end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Reactrb / Reactive-Ruby
2
2
 
3
3
  [![Join the chat at https://gitter.im/reactrb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/reactrb/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
- [![Build Status](https://travis-ci.org/reactrb/reactrb.svg)](https://travis-ci.org/reactrb/reactrb)
4
+ [![Build Status](https://travis-ci.org/reactrb/reactrb.svg?branch=master)](https://travis-ci.org/reactrb/reactrb)
5
5
  [![Code Climate](https://codeclimate.com/github/reactrb/reactrb/badges/gpa.svg)](https://codeclimate.com/github/reactrb/reactrb)
6
6
  [![Gem Version](https://badge.fury.io/rb/reactrb.svg)](https://badge.fury.io/rb/reactrb)
7
7
 
@@ -11,7 +11,7 @@
11
11
  It lets you write reactive UI components, with Ruby's elegance using the tried
12
12
  and true React.js engine. :heart:
13
13
 
14
- [**Visit reactrb.org For The Full Story**](http://reactrb.org)
14
+ [**Visit ruby-hyperloop.io For The Full Story**](http://ruby-hyperloop.io)
15
15
 
16
16
  ### Important: `react.rb` and `reactive-ruby` gems are **deprecated.** Please [read this!](#upgrading-to-reactrb)
17
17
 
@@ -23,7 +23,7 @@ Install the gem, or load the js library
23
23
  + `gem install reactrb` or
24
24
  + install (or load via cdn) [reactrb-express.js](http://github.com/reactrb/reactrb-express)
25
25
 
26
- For gem installation it is highly recommended to read [the getting started section at reactrb.org](http://reactrb.org/docs/getting-started.html)
26
+ For gem installation it is highly recommended to read the [getting started](http://ruby-hyperloop.io/get_started/) and [installation](http://ruby-hyperloop.io/installation/) guides at [ruby-hyperloop.io](http://ruby-hyperloop.io)
27
27
 
28
28
  ## Quick Overview
29
29
 
@@ -72,13 +72,10 @@ It is very unlikely that there will be any more releases of the `reactive-ruby`
72
72
  There are no syntactic or semantic breaking changes between `reactrb` v 0.8.x and
73
73
  previous versions, however the `reactrb` gem does *not* include the react-js source as previous versions did. This allows you to pick the react js source compatible with other gems and react js components you may be using.
74
74
 
75
- To upgrade, replace `reactive-ruby` with `reactrb`, both in your Gemfile, and in any `requires` in your code. You will also need to require react-js as this is no longer included in the gem.
75
+ Follow these steps to upgrade:
76
76
 
77
- If you are using react-rails then simply find anyplace where you `require 'reactrb'` and immediately before this do a `require 'react'` which will load the compatible react js file.
78
-
79
- If you are using webpack then add `react` to your manifest.
80
-
81
- If you are not using react-rails then find where you `require 'reactrb'` and immediately before this do a `require 'react-latest'` (or 'react-v13', 'react-v14' or 'react-v15')
77
+ 1. Replace `reactive-ruby` with `reactrb` both in **Gemfile** and any `require`s in your code.
78
+ 2. To include the React.js source, the suggested way is to add `require 'react/react-source'` before `require 'reactrb'`. This will use the copy of React.js source from `react-rails` gem.
82
79
 
83
80
  # Roadmap
84
81
 
data/Rakefile CHANGED
@@ -2,14 +2,19 @@ require 'bundler'
2
2
  Bundler.require
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
+ # Store the BUNDLE_GEMFILE env, since rake or rspec seems to clean it
6
+ # while invoking task.
7
+ ENV['REAL_BUNDLE_GEMFILE'] = ENV['BUNDLE_GEMFILE']
5
8
 
6
9
  require 'rspec/core/rake_task'
7
10
  require 'opal/rspec/rake_task'
8
11
 
9
12
  RSpec::Core::RakeTask.new('ruby:rspec')
10
- Opal::RSpec::RakeTask.new('opal:rspec') do |s|
13
+
14
+ Opal::RSpec::RakeTask.new('opal:rspec') do |s, task|
11
15
  s.append_path 'spec/vendor'
12
16
  s.index_path = 'spec/index.html.erb'
17
+ task.timeout = 80000 if task
13
18
  end
14
19
 
15
20
  task :test do
data/config.ru CHANGED
@@ -4,21 +4,22 @@ Bundler.require
4
4
  require "opal/rspec"
5
5
  require "opal-jquery"
6
6
 
7
- Opal.append_path File.expand_path('../spec', __FILE__)
8
-
9
- sprockets_env = Opal::RSpec::SprocketsEnvironment.new rescue nil
10
- if sprockets_env
7
+ if Opal::RSpec.const_defined?("SprocketsEnvironment")
8
+ sprockets_env = Opal::RSpec::SprocketsEnvironment.new
9
+ sprockets_env.cache = Sprockets::Cache::FileStore.new("tmp")
10
+ sprockets_env.add_spec_paths_to_sprockets
11
11
  run Opal::Server.new(sprockets: sprockets_env) { |s|
12
12
  s.main = 'opal/rspec/sprockets_runner'
13
- sprockets_env.add_spec_paths_to_sprockets
14
13
  s.debug = false
14
+ s.append_path 'spec/vendor'
15
15
  s.index_path = 'spec/index.html.erb'
16
16
  }
17
17
  else
18
18
  run Opal::Server.new { |s|
19
19
  s.main = 'opal/rspec/sprockets_runner'
20
20
  s.append_path 'spec'
21
- s.debug = true
21
+ s.append_path 'spec/vendor'
22
+ s.debug = false
22
23
  s.index_path = 'spec/index.html.erb'
23
24
  }
24
25
  end
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "opal", "~> 0.8.0"
6
+ gem "opal-rails", "~> 0.8.1"
7
+ gem "react-rails", "~> 1.3.3", :require => false
8
+
9
+ group :development do
10
+ gem "appraisal"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "opal", "~> 0.8.0"
6
+ gem "opal-rails", "~> 0.8.1"
7
+ gem "react-rails", "~> 1.6.2", :require => false
8
+
9
+ group :development do
10
+ gem "appraisal"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "opal", "~> 0.8.0"
6
+ gem "opal-rails", "~> 0.8.1"
7
+ gem "react-rails", "~> 1.8.2", :require => false
8
+
9
+ group :development do
10
+ gem "appraisal"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "opal", "~> 0.9.0"
6
+ gem "opal-rails", "~> 0.9.0"
7
+ gem "react-rails", "~> 1.3.3", :require => false
8
+
9
+ group :development do
10
+ gem "appraisal"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "opal", "~> 0.9.0"
6
+ gem "opal-rails", "~> 0.9.0"
7
+ gem "react-rails", "~> 1.6.2", :require => false
8
+
9
+ group :development do
10
+ gem "appraisal"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "opal", "~> 0.9.0"
6
+ gem "opal-rails", "~> 0.9.0"
7
+ gem "react-rails", "~> 1.8.2", :require => false
8
+
9
+ group :development do
10
+ gem "appraisal"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -1,4 +1,4 @@
1
1
  require 'opal'
2
- require 'react'
2
+ require 'react/react-source'
3
3
  require 'reactrb'
4
4
  require_tree './components'
@@ -12,7 +12,7 @@ module React
12
12
  param :controller
13
13
  param :render_params
14
14
 
15
- backtrace :on
15
+ backtrace :off
16
16
 
17
17
  def render
18
18
  paths_searched = []
@@ -0,0 +1,2 @@
1
+ // A placeholder file to prevent file not found error of requireing
2
+ // `react-server` in react/react-source
@@ -59,19 +59,19 @@ module React
59
59
  },
60
60
  componentWillReceiveProps: function(next_props) {
61
61
  var instance = this._getOpalInstance.apply(this);
62
- return #{`instance`.component_will_receive_props(`next_props`) if type.method_defined? :component_will_receive_props};
62
+ return #{`instance`.component_will_receive_props(Hash.new(`next_props`)) if type.method_defined? :component_will_receive_props};
63
63
  },
64
64
  shouldComponentUpdate: function(next_props, next_state) {
65
65
  var instance = this._getOpalInstance.apply(this);
66
- return #{`instance`.should_component_update?(`next_props`, `next_state`) if type.method_defined? :should_component_update?};
66
+ return #{`instance`.should_component_update?(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :should_component_update?};
67
67
  },
68
68
  componentWillUpdate: function(next_props, next_state) {
69
69
  var instance = this._getOpalInstance.apply(this);
70
- return #{`instance`.component_will_update(`next_props`, `next_state`) if type.method_defined? :component_will_update};
70
+ return #{`instance`.component_will_update(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :component_will_update};
71
71
  },
72
72
  componentDidUpdate: function(prev_props, prev_state) {
73
73
  var instance = this._getOpalInstance.apply(this);
74
- return #{`instance`.component_did_update(`prev_props`, `prev_state`) if type.method_defined? :component_did_update};
74
+ return #{`instance`.component_did_update(Hash.new(`prev_props`), Hash.new(`prev_state`)) if type.method_defined? :component_did_update};
75
75
  },
76
76
  componentWillUnmount: function() {
77
77
  var instance = this._getOpalInstance.apply(this);
@@ -110,16 +110,17 @@ module React
110
110
  raise "#{type} not implemented"
111
111
  end
112
112
 
113
- # Passed in properties
114
- params << convert_props(properties)
113
+ # Convert Passed in properties
114
+ properties = convert_props(properties)
115
+ params << properties.shallow_to_n
115
116
 
116
117
  # Children Nodes
117
118
  if block_given?
118
- children = [yield].flatten.each do |ele|
119
+ [yield].flatten.each do |ele|
119
120
  params << ele.to_n
120
121
  end
121
122
  end
122
- return React::Element.new(`React.createElement.apply(null, #{params})`, type, properties, block)
123
+ React::Element.new(`React.createElement.apply(null, #{params})`, type, properties, block)
123
124
  end
124
125
 
125
126
  def self.clear_component_class_cache
@@ -139,19 +140,19 @@ module React
139
140
  elsif React::HASH_ATTRIBUTES.include?(key) && value.is_a?(Hash)
140
141
  value.each { |k, v| props["#{key}-#{k.tr('_', '-')}"] = v.to_n }
141
142
  else
142
- props[React::ATTRIBUTES.include?(lower_camelize(key)) ? lower_camelize(key) : key] = value
143
+ props[React.html_attr?(lower_camelize(key)) ? lower_camelize(key) : key] = value
143
144
  end
144
145
  end
145
- props.shallow_to_n
146
+ props
146
147
  end
147
148
 
148
149
  private
149
150
 
150
151
  def self.lower_camelize(snake_cased_word)
151
- words = snake_cased_word.split("_")
152
+ words = snake_cased_word.split('_')
152
153
  result = [words.first]
153
154
  result.concat(words[1..-1].map {|word| word[0].upcase + word[1..-1] })
154
- result.join("")
155
+ result.join('')
155
156
  end
156
157
  end
157
158
  end
@@ -0,0 +1,30 @@
1
+ module React
2
+ class Children
3
+ include Enumerable
4
+
5
+ def initialize(children)
6
+ @children = children
7
+ end
8
+
9
+ def each(&block)
10
+ return to_enum(__callee__) { length } unless block_given?
11
+ return [] unless length > 0
12
+ collection = []
13
+ %x{
14
+ React.Children.forEach(#{@children}, function(context){
15
+ #{
16
+ element = React::Element.new(`context`)
17
+ block.call(element)
18
+ collection << element
19
+ }
20
+ })
21
+ }
22
+ collection
23
+ end
24
+
25
+ def length
26
+ @length ||= `React.Children.count(#{@children})`
27
+ end
28
+ alias_method :size, :length
29
+ end
30
+ end
@@ -17,6 +17,7 @@ module React
17
17
  base.include(Callbacks)
18
18
  base.include(Tags)
19
19
  base.include(DslInstanceMethods)
20
+ base.include(ShouldComponentUpdate)
20
21
  base.class_eval do
21
22
  class_attribute :initial_state
22
23
  define_callback :before_mount
@@ -42,35 +43,22 @@ module React
42
43
  @native = native_element
43
44
  end
44
45
 
45
- def render
46
- raise "no render defined"
47
- end unless method_defined?(:render)
48
-
49
- def update_react_js_state(object, name, value)
50
- if object
51
- set_state({"***_state_updated_at-***" => Time.now.to_f, "#{object.class.to_s+'.' unless object == self}#{name}" => value})
52
- else
53
- set_state({name => value})
54
- end rescue nil
55
- end
56
-
57
46
  def emit(event_name, *args)
58
- self.params["_on#{event_name.to_s.event_camelize}"].call(*args)
47
+ params["_on#{event_name.to_s.event_camelize}"].call(*args)
59
48
  end
60
49
 
61
50
  def component_will_mount
62
51
  IsomorphicHelpers.load_context(true) if IsomorphicHelpers.on_opal_client?
63
- @props_wrapper = self.class.props_wrapper.new(Hash.new(`#{@native}.props`))
64
52
  set_state! initial_state if initial_state
65
53
  State.initialize_states(self, initial_state)
66
- State.set_state_context_to(self) { self.run_callback(:before_mount) }
54
+ State.set_state_context_to(self) { run_callback(:before_mount) }
67
55
  rescue Exception => e
68
56
  self.class.process_exception(e, self)
69
57
  end
70
58
 
71
59
  def component_did_mount
72
60
  State.set_state_context_to(self) do
73
- self.run_callback(:after_mount)
61
+ run_callback(:after_mount)
74
62
  State.update_states_to_observe
75
63
  end
76
64
  rescue Exception => e
@@ -85,35 +73,8 @@ module React
85
73
  self.class.process_exception(e, self)
86
74
  end
87
75
 
88
- def props_changed?(next_props)
89
- return true unless props.keys.sort == next_props.keys.sort
90
- props.detect { |k, v| `#{next_props[k]} != #{params[k]}`}
91
- end
92
-
93
- def should_component_update?(next_props, next_state)
94
- State.set_state_context_to(self) do
95
- next_props = Hash.new(next_props)
96
- if self.respond_to?(:needs_update?)
97
- !!self.needs_update?(next_props, Hash.new(next_state))
98
- elsif false # switch to true to force updates per standard react
99
- true
100
- elsif props_changed? next_props
101
- true
102
- elsif `!next_state != !#{@native}.state`
103
- true
104
- elsif `!next_state && !#{@native}.state`
105
- false
106
- elsif `next_state["***_state_updated_at-***"] != #{@native}.state["***_state_updated_at-***"]`
107
- true
108
- else
109
- false
110
- end.to_n
111
- end
112
- end
113
-
114
76
  def component_will_update(next_props, next_state)
115
77
  State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
116
- @props_wrapper = self.class.props_wrapper.new(Hash.new(next_props), @props_wrapper)
117
78
  rescue Exception => e
118
79
  self.class.process_exception(e, self)
119
80
  end
@@ -138,11 +99,32 @@ module React
138
99
 
139
100
  attr_reader :waiting_on_resources
140
101
 
102
+ def update_react_js_state(object, name, value)
103
+ if object
104
+ name = "#{object.class}.#{name}" unless object == self
105
+ set_state(
106
+ '***_state_updated_at-***' => Time.now.to_f,
107
+ name => value
108
+ )
109
+ else
110
+ set_state name => value
111
+ end
112
+ end
113
+
114
+ def render
115
+ raise 'no render defined'
116
+ end unless method_defined?(:render)
117
+
141
118
  def _render_wrapper
142
- State.set_state_context_to(self) do
143
- React::RenderingContext.render(nil) {render || ""}.tap { |element| @waiting_on_resources = element.waiting_on_resources if element.respond_to? :waiting_on_resources }
119
+ State.set_state_context_to(self, true) do
120
+ element = React::RenderingContext.render(nil) { render || '' }
121
+ @waiting_on_resources =
122
+ element.waiting_on_resources if element.respond_to? :waiting_on_resources
123
+ element
144
124
  end
125
+ # rubocop:disable Lint/RescueException # we want to catch all exceptions regardless
145
126
  rescue Exception => e
127
+ # rubocop:enable Lint/RescueException
146
128
  self.class.process_exception(e, self)
147
129
  end
148
130
 
@@ -153,6 +135,5 @@ module React
153
135
  def define_state(*args, &block)
154
136
  State.initialize_states(self, self.class.define_state(*args, &block))
155
137
  end
156
-
157
138
  end
158
139
  end