hyper-react 0.10.0 → 0.11.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.
- checksums.yaml +4 -4
- data/.travis.yml +26 -4
- data/Appraisals +3 -2
- data/CHANGELOG.md +19 -0
- data/README.md +3 -3
- data/config.ru +2 -1
- data/gemfiles/opal_0.10_react_13.gemfile +13 -0
- data/gemfiles/opal_0.10_react_14.gemfile +13 -0
- data/gemfiles/opal_0.10_react_15.gemfile +13 -0
- data/gemfiles/opal_0.8_react_15.gemfile +1 -1
- data/gemfiles/opal_0.9_react_15.gemfile +1 -1
- data/hyper-react.gemspec +1 -1
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -1
- data/lib/hyper-react.rb +2 -1
- data/lib/react/api.rb +3 -2
- data/lib/react/component/class_methods.rb +2 -2
- data/lib/react/component/props_wrapper.rb +2 -2
- data/lib/react/element.rb +1 -1
- data/lib/react/ext/opal-jquery/element.rb +26 -0
- data/lib/react/state.rb +6 -5
- data/lib/react/test/matchers/render_html_matcher.rb +5 -0
- data/lib/react/test/session.rb +14 -23
- data/lib/react/test/utils.rb +25 -0
- data/lib/react/top_level.rb +12 -28
- data/lib/react/top_level_render.rb +29 -0
- data/lib/reactive-ruby/isomorphic_helpers.rb +2 -2
- data/lib/reactive-ruby/version.rb +1 -1
- data/spec/index.html.erb +1 -0
- data/spec/react/children_spec.rb +1 -1
- data/spec/react/component/base_spec.rb +2 -2
- data/spec/react/component_spec.rb +74 -73
- data/spec/react/dsl_spec.rb +24 -21
- data/spec/react/element_spec.rb +7 -7
- data/spec/react/event_spec.rb +2 -2
- data/spec/react/native_library_spec.rb +20 -24
- data/spec/react/observable_spec.rb +36 -1
- data/spec/react/opal_jquery_extensions_spec.rb +48 -46
- data/spec/react/param_declaration_spec.rb +8 -8
- data/spec/react/react_spec.rb +41 -28
- data/spec/react/test/rspec_spec.rb +1 -1
- data/spec/react/test/session_spec.rb +8 -20
- data/spec/react/test/utils_spec.rb +11 -28
- data/spec/react/top_level_component_spec.rb +7 -2
- data/spec/react/tutorial/tutorial_spec.rb +2 -2
- data/spec/reactive-ruby/component_loader_spec.rb +10 -4
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +6 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/react/spec_helpers.rb +1 -21
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce1a3a5b1c6327f4acec7ec587a1bca16c12738
|
4
|
+
data.tar.gz: 9268144dd28594592f79c11a99812876fd24c905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76a870924c4762816df9eda0f50edba5e4a65bc5158490f08c11953752cd022dae5da7ff67f4933f9cd0e7c28d10700822872a162245fb247b359fb581589929
|
7
|
+
data.tar.gz: 65fbb0f11b47c7bb1d5182d5a80e5109f5b748b7b87f43125b0937b7a773c09364956ae0a5dd44ba7965ff8e8acdd25ddad3043371e42d4915d2061e66412ae2
|
data/.travis.yml
CHANGED
@@ -6,9 +6,8 @@ rvm:
|
|
6
6
|
- jruby-19mode
|
7
7
|
before_script:
|
8
8
|
- phantomjs --version
|
9
|
-
|
10
|
-
-
|
11
|
-
- bundle exec rake
|
9
|
+
env:
|
10
|
+
- PHANTOMJS_VERSION=1.9.8
|
12
11
|
gemfile:
|
13
12
|
- gemfiles/opal_0.8_react_13.gemfile
|
14
13
|
- gemfiles/opal_0.8_react_14.gemfile
|
@@ -16,7 +15,20 @@ gemfile:
|
|
16
15
|
- gemfiles/opal_0.9_react_13.gemfile
|
17
16
|
- gemfiles/opal_0.9_react_14.gemfile
|
18
17
|
- gemfiles/opal_0.9_react_15.gemfile
|
19
|
-
|
18
|
+
cache:
|
19
|
+
directories:
|
20
|
+
- "travis_phantomjs"
|
21
|
+
before_install:
|
22
|
+
- "phantomjs --version"
|
23
|
+
- "export PATH=$PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin:$PATH"
|
24
|
+
- "phantomjs --version"
|
25
|
+
- "if [ $(phantomjs --version) != $PHANTOMJS_VERSION ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi"
|
26
|
+
- "if [ $(phantomjs --version) != $PHANTOMJS_VERSION ]; then wget https://github.com/Medium/phantomjs/releases/download/v$PHANTOMJS_VERSION/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2; fi"
|
27
|
+
- "if [ $(phantomjs --version) != $PHANTOMJS_VERSION ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi"
|
28
|
+
- "phantomjs --version"
|
29
|
+
script:
|
30
|
+
- bundle exec rake test_app
|
31
|
+
- bundle exec rake
|
20
32
|
# These two setup seems to run indefinitely long
|
21
33
|
# further investigation required.
|
22
34
|
matrix:
|
@@ -27,3 +39,13 @@ matrix:
|
|
27
39
|
gemfile: gemfiles/opal_0.9_react_14.gemfile
|
28
40
|
- rvm: jruby-19mode
|
29
41
|
gemfile: gemfiles/opal_0.9_react_15.gemfile
|
42
|
+
include:
|
43
|
+
- rvm: 2.1
|
44
|
+
env: PHANTOMJS_VERSION=2.1.1
|
45
|
+
gemfile: gemfiles/opal_0.10_react_13.gemfile
|
46
|
+
- rvm: 2.1
|
47
|
+
env: PHANTOMJS_VERSION=2.1.1
|
48
|
+
gemfile: gemfiles/opal_0.10_react_14.gemfile
|
49
|
+
- rvm: 2.1
|
50
|
+
env: PHANTOMJS_VERSION=2.1.1
|
51
|
+
gemfile: gemfiles/opal_0.10_react_15.gemfile
|
data/Appraisals
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
opal_versions = ['0.8', '0.9']
|
1
|
+
opal_versions = ['0.8', '0.9', '0.10']
|
2
2
|
react_versions_map = {
|
3
3
|
'13' => '~> 1.3.3',
|
4
4
|
'14' => '~> 1.6.2',
|
5
|
-
'15' => '~> 1.
|
5
|
+
'15' => '~> 1.10.0'
|
6
6
|
}
|
7
7
|
opal_rails_versions_map = {
|
8
8
|
'0.8' => '~> 0.8.1',
|
9
9
|
'0.9' => '~> 0.9.0',
|
10
|
+
'0.10' => '~> 0.9.0',
|
10
11
|
}
|
11
12
|
|
12
13
|
opal_versions.each do |opal_v|
|
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,25 @@ Whitespace conventions:
|
|
18
18
|
- 1 spaces before normal text
|
19
19
|
-->
|
20
20
|
|
21
|
+
## [0.11.0] - 2016-12-13
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- The whole opal-activesuppport is not loaded by default now. This gave us about 18% size reduction on the built file. If your code rely on any of the module which is not required by hyper-react, you need to require it yourself. (#135)
|
26
|
+
|
27
|
+
### Deprecated
|
28
|
+
|
29
|
+
- Current `React.render` behavior is deprecated. Require `"react/top_level_render"` to get the updated behavior. (#187)
|
30
|
+
- `React.is_valid_element` is deprecated in favor of `React.is_valid_element?`.
|
31
|
+
- `expect(component).to render('<div />')` is now deprecated in favor of `expect(component).to render_static_html('<div />')`, which is much clearer.
|
32
|
+
|
33
|
+
### Fixed
|
34
|
+
|
35
|
+
- `ReferenceError: window is not defined` error in prerender context with react-rails v1.10.0. (#196)
|
36
|
+
- State might not be updated using `React::Observable` from a param. (#175)
|
37
|
+
- Arity checking failed for `_react_param_conversion` & `React::Element#initialize` (#167)
|
38
|
+
|
39
|
+
|
21
40
|
## [0.10.0] - 2016-10-30
|
22
41
|
|
23
42
|
### Changed
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# hyper-react
|
2
2
|
|
3
3
|
[](https://gitter.im/reactrb/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
-
[](https://travis-ci.org/ruby-hyperloop/hyper-react)
|
5
5
|
[](https://codeclimate.com/github/reactrb/reactrb)
|
6
|
-
[](https://badge.fury.io/rb/hyper-react)
|
7
7
|
|
8
8
|
**hyper-react is an [Opal Ruby](http://opalrb.org) wrapper of
|
9
9
|
[React.js library](https://facebook.github.io/react)**.
|
@@ -107,7 +107,7 @@ Note that these are very simple examples, for the purpose of showing how to conf
|
|
107
107
|
|
108
108
|
1. Run `bundle exec rake test_app` to generate a dummy test app.
|
109
109
|
2. `bundle exec appraisal install` to generate separate gemfiles for different environments.
|
110
|
-
2. `bundle exec appraisal opal-0.
|
110
|
+
2. `bundle exec appraisal opal-0.10-react-15 rake` to run test for opal-0.10 & react-v0.15.
|
111
111
|
|
112
112
|
## Contributions
|
113
113
|
|
data/config.ru
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "opal", "~> 0.10.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.10.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.10.0"
|
6
|
+
gem "opal-rails", "~> 0.9.0"
|
7
|
+
gem "react-rails", "~> 1.10.0", :require => false
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem "appraisal"
|
11
|
+
end
|
12
|
+
|
13
|
+
gemspec :path => "../"
|
data/hyper-react.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency 'opal', '>= 0.8.0'
|
22
22
|
s.add_dependency 'opal-activesupport', '>= 0.2.0'
|
23
23
|
s.add_dependency 'react-rails'
|
24
|
-
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'rake', '< 11.0'
|
25
25
|
s.add_development_dependency 'rspec-rails', '3.3.3'
|
26
26
|
s.add_development_dependency 'timecop'
|
27
27
|
s.add_development_dependency 'opal-rspec'
|
data/lib/hyper-react.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
if RUBY_ENGINE == 'opal'
|
4
|
-
if `
|
4
|
+
if `Opal.global.React === undefined || Opal.global.React.version === undefined`
|
5
5
|
raise [
|
6
6
|
"No React.js Available",
|
7
7
|
"",
|
@@ -28,6 +28,7 @@ if RUBY_ENGINE == 'opal'
|
|
28
28
|
require 'react/rendering_context'
|
29
29
|
require 'react/state'
|
30
30
|
require 'react/object'
|
31
|
+
require "react/ext/opal-jquery/element"
|
31
32
|
require 'reactive-ruby/isomorphic_helpers'
|
32
33
|
require 'rails-helpers/top_level_rails_component'
|
33
34
|
require 'reactive-ruby/version'
|
data/lib/react/api.rb
CHANGED
@@ -27,14 +27,15 @@ module React
|
|
27
27
|
(`!!#{component}.prototype.isReactComponent` ||
|
28
28
|
`!!#{component}.prototype.render`)
|
29
29
|
is_functional_component = `typeof #{component} === "function"`
|
30
|
-
is_not_using_react_v13 = `!
|
30
|
+
is_not_using_react_v13 = `!Opal.global.React.version.match(/0\.13/)`
|
31
31
|
unless is_component_class || (is_not_using_react_v13 && is_functional_component)
|
32
32
|
raise 'does not appear to be a native react component'
|
33
33
|
end
|
34
34
|
component
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.native_react_component?(name)
|
37
|
+
def self.native_react_component?(name = nil)
|
38
|
+
return false unless name
|
38
39
|
eval_native_react_component(name)
|
39
40
|
rescue
|
40
41
|
nil
|
@@ -181,8 +181,8 @@ module React
|
|
181
181
|
def export_component(opts = {})
|
182
182
|
export_name = (opts[:as] || name).split('::')
|
183
183
|
first_name = export_name.first
|
184
|
-
Native(`
|
185
|
-
Native(`
|
184
|
+
Native(`Opal.global`)[first_name] = add_item_to_tree(
|
185
|
+
Native(`Opal.global`)[first_name],
|
186
186
|
[React::API.create_native_react_class(self)] + export_name[1..-1].reverse
|
187
187
|
).to_n
|
188
188
|
end
|
@@ -35,11 +35,11 @@ module React
|
|
35
35
|
define_method("#{name}") do
|
36
36
|
fetch_from_cache(name) do
|
37
37
|
if param_type.respond_to? :_react_param_conversion
|
38
|
-
param_type._react_param_conversion props[name]
|
38
|
+
param_type._react_param_conversion props[name], nil
|
39
39
|
elsif param_type.is_a?(Array) &&
|
40
40
|
param_type[0].respond_to?(:_react_param_conversion)
|
41
41
|
props[name].collect do |param|
|
42
|
-
param_type[0]._react_param_conversion param
|
42
|
+
param_type[0]._react_param_conversion param, nil
|
43
43
|
end
|
44
44
|
else
|
45
45
|
props[name]
|
data/lib/react/element.rb
CHANGED
@@ -25,7 +25,7 @@ module React
|
|
25
25
|
|
26
26
|
attr_accessor :waiting_on_resources
|
27
27
|
|
28
|
-
def initialize(native_element, type, properties, block)
|
28
|
+
def initialize(native_element, type = nil, properties = {}, block = nil)
|
29
29
|
@type = type
|
30
30
|
@properties = (`typeof #{properties} === 'undefined'` ? nil : properties) || {}
|
31
31
|
@block = block
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Element.instance_eval do
|
2
|
+
def self.find(selector)
|
3
|
+
selector = begin
|
4
|
+
selector.dom_node
|
5
|
+
rescue
|
6
|
+
selector
|
7
|
+
end if `#{selector}.$dom_node !== undefined`
|
8
|
+
`$(#{selector})`
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.[](selector)
|
12
|
+
find(selector)
|
13
|
+
end
|
14
|
+
|
15
|
+
define_method :render do |container = nil, params = {}, &block|
|
16
|
+
if `#{self.to_n}._reactrb_component_class === undefined`
|
17
|
+
`#{self.to_n}._reactrb_component_class = #{Class.new(React::Component::Base)}`
|
18
|
+
end
|
19
|
+
klass = `#{self.to_n}._reactrb_component_class`
|
20
|
+
klass.class_eval do
|
21
|
+
render(container, params, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
React.render(React.create_element(`#{self.to_n}._reactrb_component_class`), self)
|
25
|
+
end
|
26
|
+
end if Object.const_defined?('Element')
|
data/lib/react/state.rb
CHANGED
@@ -15,15 +15,16 @@ module React
|
|
15
15
|
|
16
16
|
def method_missing(method, *args)
|
17
17
|
if match = method.match(/^(.+)\!$/)
|
18
|
+
key_name = $1
|
18
19
|
if args.count > 0
|
19
20
|
current_value = State.get_state(@from, match[1])
|
20
|
-
State.set_state(@from,
|
21
|
+
State.set_state(@from, key_name, args[0])
|
21
22
|
current_value
|
22
23
|
else
|
23
24
|
current_state = State.get_state(@from, match[1])
|
24
|
-
State.set_state(@from,
|
25
|
+
State.set_state(@from, key_name, current_state)
|
25
26
|
Observable.new(current_state) do |update|
|
26
|
-
State.set_state(@from,
|
27
|
+
State.set_state(@from, key_name, update)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
else
|
@@ -158,7 +159,7 @@ module React
|
|
158
159
|
end
|
159
160
|
|
160
161
|
def set_state_context_to(observer, rendering = nil) # wrap all execution that may set or get states in a block so we know which observer is executing
|
161
|
-
if `typeof
|
162
|
+
if `typeof Opal.global.reactive_ruby_timing !== 'undefined'`
|
162
163
|
@nesting_level = (@nesting_level || 0) + 1
|
163
164
|
start_time = Time.now.to_f
|
164
165
|
observer_name = (observer.class.respond_to?(:name) ? observer.class.name : observer.to_s) rescue "object:#{observer.object_id}"
|
@@ -171,7 +172,7 @@ module React
|
|
171
172
|
ensure
|
172
173
|
@current_observer = saved_current_observer
|
173
174
|
@rendering_level -= 1 if rendering
|
174
|
-
@nesting_level = [0, @nesting_level - 1].max if `typeof
|
175
|
+
@nesting_level = [0, @nesting_level - 1].max if `typeof Opal.global.reactive_ruby_timing !== 'undefined'`
|
175
176
|
return_value
|
176
177
|
end
|
177
178
|
|
@@ -41,7 +41,12 @@ module React
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def render_static_html(*args)
|
45
|
+
RenderHTMLMatcher.new(*args)
|
46
|
+
end
|
47
|
+
|
44
48
|
def render(*args)
|
49
|
+
%x{ console.error("Warning: `render` matcher is deprecated in favor of `render_static_html`."); }
|
45
50
|
RenderHTMLMatcher.new(*args)
|
46
51
|
end
|
47
52
|
end
|
data/lib/react/test/session.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module React
|
2
2
|
module Test
|
3
3
|
class Session
|
4
|
-
DSL_METHODS = %i[mount instance
|
5
|
-
force_update! html].freeze
|
4
|
+
DSL_METHODS = %i[mount instance update_params html].freeze
|
6
5
|
|
7
6
|
def mount(component_klass, params = {})
|
8
7
|
@element = React.create_element(component_klass, params)
|
@@ -11,35 +10,27 @@ module React
|
|
11
10
|
|
12
11
|
def instance
|
13
12
|
unless @instance
|
14
|
-
@
|
15
|
-
@instance =
|
13
|
+
@container = `document.createElement('div')`
|
14
|
+
@instance = React.render(@element, @container)
|
16
15
|
end
|
17
16
|
@instance
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
21
|
-
@
|
22
|
-
|
23
|
-
|
24
|
-
def element
|
25
|
-
@element
|
26
|
-
end
|
27
|
-
|
28
|
-
def update_params(params)
|
29
|
-
cloned_element = React::Element.new(`React.cloneElement(#{self.element.to_n}, #{params.to_n})`)
|
30
|
-
prev_container = `#{self.instance.dom_node}.parentNode`
|
31
|
-
React.render(cloned_element, prev_container)
|
19
|
+
def update_params(params, &block)
|
20
|
+
cloned_element = React::Element.new(`React.cloneElement(#{@element.to_n}, #{params.to_n})`)
|
21
|
+
React.render(cloned_element, @container, &block)
|
32
22
|
nil
|
33
23
|
end
|
34
24
|
|
35
|
-
def force_update!
|
36
|
-
native.force_update!
|
37
|
-
end
|
38
|
-
|
39
25
|
def html
|
40
|
-
|
41
|
-
|
42
|
-
|
26
|
+
html = `#@container.innerHTML`
|
27
|
+
%x{
|
28
|
+
var REGEX_REMOVE_ROOT_IDS = /\s?data-reactroot="[^"]*"/g;
|
29
|
+
var REGEX_REMOVE_IDS = /\s?data-reactid="[^"]+"/g;
|
30
|
+
html = html.replace(REGEX_REMOVE_ROOT_IDS, '');
|
31
|
+
html = html.replace(REGEX_REMOVE_IDS, '');
|
32
|
+
}
|
33
|
+
return html
|
43
34
|
end
|
44
35
|
end
|
45
36
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module React
|
2
|
+
module Test
|
3
|
+
class Utils
|
4
|
+
`var ReactTestUtils = React.addons.TestUtils`
|
5
|
+
|
6
|
+
def self.render_into_document(element, options = {})
|
7
|
+
raise "You should pass a valid React::Element" unless React.is_valid_element?(element)
|
8
|
+
native_instance = `ReactTestUtils.renderIntoDocument(#{element.to_n})`
|
9
|
+
|
10
|
+
if `#{native_instance}._getOpalInstance !== undefined`
|
11
|
+
`#{native_instance}._getOpalInstance()`
|
12
|
+
elsif `ReactTestUtils.isDOMComponent(#{native_instance}) && React.findDOMNode !== undefined`
|
13
|
+
`React.findDOMNode(#{native_instance})`
|
14
|
+
else
|
15
|
+
native_instance
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.simulate(event, element, params = {})
|
20
|
+
simulator = Native(`ReactTestUtils.Simulate`)
|
21
|
+
simulator[event.to_s].call(`element.$dom_node === undefined` ? element : element.dom_node, params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|