Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 7ba014d

Browse files
authored
Merge pull request #164 from reactrb/merge-0-8
Let's merge 0-8-stable to master
2 parents 46ddcbc + 45906da commit 7ba014d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+65304
-20300
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ node_modules
3131

3232
spec/test_app
3333
Gemfile.lock
34+
35+
/gemfiles/*.lock
36+
/tmp

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1154,3 +1154,6 @@ Style/WordArray:
11541154
Description: 'Use %w or %W for arrays of words.'
11551155
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w'
11561156
Enabled: false
1157+
1158+
Style/CommandLiteral:
1159+
EnforcedStyle: mixed

.travis.yml

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ rvm:
44
- 2.0.0
55
- 2.1
66
- jruby-19mode
7+
before_script:
8+
- phantomjs --version
79
script:
810
- bundle exec rake test_app
911
- 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

Appraisals

+20
Original file line numberDiff line numberDiff line change
@@ -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

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ Whitespace conventions:
1818
- 1 spaces before normal text
1919
-->
2020

21+
## [0.8.9] - Unreleased
22+
23+
### Fixed
24+
25+
- Gets rid of react warnings about updating state during render (#155)
26+
- Multiple HAML classes (i.e. div.foo.bar) was not working (regression introduced in 0.8.8)
27+
- Don't send nil (null) to form components as the value string (#157)
28+
- Process `params` (props) correctly when using `Element#on` or `Element#render` (#158)
29+
- Deprecate shallow param compare (#156)
30+
31+
2132
## [0.8.8] - 2016-07-13
2233

2334
### Added

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
source 'https://rubygems.org'
22
gemspec
3+
4+
group :development do
5+
gem "appraisal"
6+
end

Rakefile

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@ require 'bundler'
22
Bundler.require
33
Bundler::GemHelper.install_tasks
44

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']
58

69
require 'rspec/core/rake_task'
710
require 'opal/rspec/rake_task'
811

12+
begin
13+
require "react-rails"
14+
rescue NameError
15+
end
16+
917
RSpec::Core::RakeTask.new('ruby:rspec')
10-
Opal::RSpec::RakeTask.new('opal:rspec') do |s|
18+
19+
Opal::RSpec::RakeTask.new('opal:rspec') do |s, task|
20+
s.append_path React::Rails::AssetVariant.new(addons: true).react_directory
1121
s.append_path 'spec/vendor'
1222
s.index_path = 'spec/index.html.erb'
23+
task.timeout = 80000 if task
1324
end
1425

1526
task :test do

component-name-lookup.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#### Notes on how component names are looked up
2+
3+
Given:
4+
5+
```ruby
6+
7+
class Blat < React::Component::Base
8+
9+
render do
10+
Bar()
11+
Foo::Bar()
12+
end
13+
14+
end
15+
16+
class Bar < React::Component::Base
17+
end
18+
19+
module Foo
20+
21+
class Bar < React::Component::Base
22+
23+
render do
24+
Blat()
25+
Baz()
26+
end
27+
end
28+
29+
class Baz < React::Component::Base
30+
end
31+
32+
end
33+
```
34+
35+
The problem is that method lookup is different than constant lookup. We can prove it by running this code:
36+
37+
```ruby
38+
def try_it(test, &block)
39+
puts "trying #{test}"
40+
result = yield
41+
puts "success#{': '+result.to_s if result}"
42+
rescue Exception => e
43+
puts "failed: #{e}"
44+
ensure
45+
puts "---------------------------------"
46+
end
47+
48+
module Boom
49+
50+
Bar = 12
51+
52+
def self.Bar
53+
puts " Boom::Bar says hi"
54+
end
55+
56+
class Baz
57+
def doit
58+
try_it("Bar()") { Bar() }
59+
try_it("Boom::Bar()") {Boom::Bar()}
60+
try_it("Bar") { Bar }
61+
try_it("Boom::Bar") { Boom::Bar }
62+
end
63+
end
64+
end
65+
66+
67+
68+
Boom::Baz.new.doit
69+
```
70+
71+
which prints:
72+
73+
```text
74+
trying Bar()
75+
failed: Bar: undefined method `Bar' for #<Boom::Baz:0x774>
76+
---------------------------------
77+
trying Boom::Bar()
78+
Boom::Bar says hi
79+
success
80+
---------------------------------
81+
trying Bar
82+
success: 12
83+
---------------------------------
84+
trying Boom::Bar
85+
success: 12
86+
---------------------------------
87+
```
88+
89+
[try-it](http://opalrb.org/try/?code:def%20try_it(test%2C%20%26block)%0A%20%20puts%20%22trying%20%23%7Btest%7D%22%0A%20%20result%20%3D%20yield%0A%20%20puts%20%22success%23%7B%27%3A%20%27%2Bresult.to_s%20if%20result%7D%22%0Arescue%20Exception%20%3D%3E%20e%0A%20%20puts%20%22failed%3A%20%23%7Be%7D%22%0Aensure%0A%20%20puts%20%22---------------------------------%22%0Aend%0A%0Amodule%20Boom%0A%20%20%0A%20%20Bar%20%3D%2012%0A%20%20%0A%20%20def%20self.Bar%0A%20%20%20%20puts%20%22%20%20%20Boom%3A%3ABar%20says%20hi%22%0A%20%20end%0A%0A%20%20class%20Baz%0A%20%20%20%20def%20doit%0A%20%20%20%20%20%20try_it(%22Bar()%22)%20%7B%20Bar()%20%7D%0A%20%20%20%20%20%20try_it(%22Boom%3A%3ABar()%22)%20%7BBoom%3A%3ABar()%7D%0A%20%20%20%20%20%20try_it(%22Bar%22)%20%7B%20Bar%20%7D%0A%20%20%20%20%20%20try_it(%22Boom%3A%3ABar%22)%20%7B%20Boom%3A%3ABar%20%7D%0A%20%20%20%20end%0A%20%20end%0Aend%0A%20%20%0A%0A%0ABoom%3A%3ABaz.new.doit)
90+
91+
92+
What we need to do is:
93+
94+
1. when defining a component class `Foo`, also define in the same scope that Foo is being defined a method `self.Foo` that will accept Foo's params and child block, and render it.
95+
96+
2. As long as a name is qualified with at least one scope (i.e. `ModName::Foo()`) everything will work out, but if we say just `Foo()` then the only way I believe out of this is to handle it via method_missing, and let method_missing do a const_get on the method_name (which will return the class) and then render that component.
97+
98+
#### details
99+
100+
To define `self.Foo` in the same scope level as the class `Foo`, we need code like this:
101+
102+
```ruby
103+
def register_component_dsl_method(component)
104+
split_name = component.name && component.name.split('::')
105+
return unless split_name && split_name.length > 2
106+
component_name = split_name.last
107+
parent = split_name.inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }[-2]
108+
class << parent
109+
define_method component_name do |*args, &block|
110+
React::RenderingContext.render(name, *args, &block)
111+
end
112+
define_method "#{component_name}_as_node" do |*args, &block|
113+
React::Component.deprecation_warning("..._as_node is deprecated. Render component and then use the .node method instead")
114+
send(component_name, *args, &block).node
115+
end
116+
end
117+
end
118+
119+
module React
120+
module Component
121+
def self.included(base)
122+
...
123+
register_component_dsl_method(base.name)
124+
end
125+
end
126+
end
127+
```
128+
129+
The component's method_missing function will look like this:
130+
131+
```ruby
132+
def method_missing(name, *args, &block)
133+
if name =~ /_as_node$/
134+
React::Component.deprecation_warning("..._as_node is deprecated. Render component and then use the .node method instead")
135+
method_missing(name.gsub(/_as_node$/,""), *args, &block).node
136+
else
137+
component = const_get name if defined? name
138+
React::RenderingContext.render(nil, component, *args, &block)
139+
end
140+
end
141+
```
142+
143+
### other related issues
144+
145+
The Kernel#p method conflicts with the <p> tag. However the p method can be invoked on any object so we are going to go ahead and use it, and deprecate the para method.

config.ru

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
require 'bundler'
22
Bundler.require
33

4-
require "opal-rspec"
5-
require "react/source"
4+
require "opal/rspec"
5+
require "opal-jquery"
66

7-
Opal.append_path File.expand_path('../spec', __FILE__)
7+
begin
8+
require "react-rails"
9+
rescue NameError
10+
end
811

9-
run Opal::Server.new { |s|
10-
s.main = 'opal/rspec/sprockets_runner'
11-
s.append_path 'spec'
12-
s.append_path File.dirname(::React::Source.bundled_path_for("react-with-addons.js"))
13-
s.debug = true
14-
s.index_path = 'spec/reactjs/index.html.erb'
15-
}
12+
if Opal::RSpec.const_defined?("SprocketsEnvironment")
13+
sprockets_env = Opal::RSpec::SprocketsEnvironment.new
14+
sprockets_env.cache = Sprockets::Cache::FileStore.new("tmp")
15+
sprockets_env.add_spec_paths_to_sprockets
16+
run Opal::Server.new(sprockets: sprockets_env) { |s|
17+
s.main = 'opal/rspec/sprockets_runner'
18+
s.append_path React::Rails::AssetVariant.new(addons: true).react_directory
19+
s.debug = false
20+
s.append_path 'spec/vendor'
21+
s.index_path = 'spec/index.html.erb'
22+
}
23+
else
24+
run Opal::Server.new { |s|
25+
s.main = 'opal/rspec/sprockets_runner'
26+
s.append_path React::Rails::AssetVariant.new(addons: true).react_directory
27+
s.append_path 'spec'
28+
s.append_path 'spec/vendor'
29+
s.debug = false
30+
s.index_path = 'spec/index.html.erb'
31+
}
32+
end

gemfiles/opal_0.8_react_13.gemfile

+13
Original file line numberDiff line numberDiff line change
@@ -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 => "../"

gemfiles/opal_0.8_react_14.gemfile

+13
Original file line numberDiff line numberDiff line change
@@ -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 => "../"

gemfiles/opal_0.8_react_15.gemfile

+13
Original file line numberDiff line numberDiff line change
@@ -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 => "../"

gemfiles/opal_0.9_react_13.gemfile

+13
Original file line numberDiff line numberDiff line change
@@ -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 => "../"

gemfiles/opal_0.9_react_14.gemfile

+13
Original file line numberDiff line numberDiff line change
@@ -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 => "../"

gemfiles/opal_0.9_react_15.gemfile

+13
Original file line numberDiff line numberDiff line change
@@ -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 => "../"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
require 'opal'
2+
require 'react'
23
require 'reactive-ruby'
34
require_tree './components'

lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb

Whitespace-only changes.

0 commit comments

Comments
 (0)