hyper-react 0.11.0 → 0.12.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/.rubocop.yml +1 -1
- data/.travis.yml +11 -0
- data/Appraisals +10 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +2 -0
- data/README.md +7 -0
- data/gemfiles/opal_0.10_react_13.gemfile +4 -0
- data/gemfiles/opal_0.10_react_14.gemfile +4 -0
- data/gemfiles/opal_0.10_react_15.gemfile +4 -0
- data/gemfiles/opal_0.8_react_13.gemfile +4 -0
- data/gemfiles/opal_0.8_react_14.gemfile +4 -0
- data/gemfiles/opal_0.8_react_15.gemfile +4 -0
- data/gemfiles/opal_0.9_react_13.gemfile +4 -0
- data/gemfiles/opal_0.9_react_14.gemfile +4 -0
- data/gemfiles/opal_0.9_react_15.gemfile +4 -0
- data/gemfiles/opal_master_react_15.gemfile +18 -0
- data/hyper-react.gemspec +4 -0
- data/lib/hyper-react.rb +24 -4
- data/lib/rails-helpers/top_level_rails_component.rb +1 -1
- data/lib/react/api.rb +10 -0
- data/lib/react/component.rb +135 -106
- data/lib/react/component/base.rb +5 -1
- data/lib/react/component/class_methods.rb +12 -37
- data/lib/react/component/dsl_instance_methods.rb +0 -4
- data/lib/react/component/props_wrapper.rb +0 -5
- data/lib/react/component/should_component_update.rb +1 -5
- data/lib/react/component/tags.rb +7 -22
- data/lib/react/config.rb +5 -0
- data/lib/react/config/client.rb.erb +19 -0
- data/lib/react/config/server.rb +20 -0
- data/lib/react/element.rb +1 -0
- data/lib/react/native_library.rb +2 -7
- data/lib/react/react-source-browser.rb +3 -0
- data/lib/react/react-source-server.rb +3 -0
- data/lib/react/react-source.rb +12 -1
- data/lib/react/ref_callback.rb +31 -0
- data/lib/react/rendering_context.rb +9 -9
- data/lib/react/server.rb +23 -0
- data/lib/react/state_wrapper.rb +23 -0
- data/lib/react/test/matchers/render_html_matcher.rb +4 -2
- data/lib/react/top_level.rb +2 -0
- data/lib/reactive-ruby/component_loader.rb +2 -1
- data/lib/reactive-ruby/isomorphic_helpers.rb +10 -0
- data/lib/reactive-ruby/version.rb +1 -1
- data/lib/reactrb/auto-import.rb +2 -7
- data/spec/react/callbacks_spec.rb +8 -7
- data/spec/react/component_spec.rb +24 -13
- data/spec/react/dsl_spec.rb +12 -8
- data/spec/react/element_spec.rb +7 -7
- data/spec/react/native_library_spec.rb +25 -43
- data/spec/react/param_declaration_spec.rb +9 -0
- data/spec/react/react_spec.rb +0 -7
- data/spec/react/refs_callback_spec.rb +56 -0
- data/spec/react/server_spec.rb +25 -0
- data/spec/react/state_spec.rb +3 -3
- data/spec/react/top_level_component_spec.rb +1 -1
- data/spec/spec_helper.rb +31 -1
- metadata +72 -9
- data/lib/react/observable.rb +0 -29
- data/lib/react/state.rb +0 -191
- data/lib/sources/react-latest.js +0 -21169
- data/lib/sources/react-v13.js +0 -21645
- data/lib/sources/react-v14.js +0 -20821
- data/lib/sources/react-v15.js +0 -21170
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 513e80e952999575e80a5b1456a712a2aa895247
|
|
4
|
+
data.tar.gz: 75ac40ec7d8036255310753b9b47ff923db5b4fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70cb674bdd87a7cd74ad25e731cb2ac468735f8e9a7dc5344b44bb94bec22a812f21c3c38c0acd5a4ae03502480551aa6465c73d0bd2ab3cf567d0202696d7c4
|
|
7
|
+
data.tar.gz: baac4f594a9ba1ff729f8b1f519cd50a66d1eeb47683a4b19b70f4769999bad0df71bde08849d35c34139b16db3effc924718c6e148c17c854b95131c1829418
|
data/.rubocop.yml
CHANGED
|
@@ -716,7 +716,7 @@ Style/LineEndConcatenation:
|
|
|
716
716
|
line end.
|
|
717
717
|
Enabled: false
|
|
718
718
|
|
|
719
|
-
Style/
|
|
719
|
+
Style/MethodCallWithoutArgsParentheses:
|
|
720
720
|
Description: 'Do not use parentheses for method calls with no arguments.'
|
|
721
721
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
|
|
722
722
|
Enabled: false
|
data/.travis.yml
CHANGED
|
@@ -18,6 +18,9 @@ gemfile:
|
|
|
18
18
|
cache:
|
|
19
19
|
directories:
|
|
20
20
|
- "travis_phantomjs"
|
|
21
|
+
branches:
|
|
22
|
+
only:
|
|
23
|
+
- master
|
|
21
24
|
before_install:
|
|
22
25
|
- "phantomjs --version"
|
|
23
26
|
- "export PATH=$PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin:$PATH"
|
|
@@ -26,6 +29,7 @@ before_install:
|
|
|
26
29
|
- "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
30
|
- "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
31
|
- "phantomjs --version"
|
|
32
|
+
- gem install bundler -v 1.13.7
|
|
29
33
|
script:
|
|
30
34
|
- bundle exec rake test_app
|
|
31
35
|
- bundle exec rake
|
|
@@ -49,3 +53,10 @@ matrix:
|
|
|
49
53
|
- rvm: 2.1
|
|
50
54
|
env: PHANTOMJS_VERSION=2.1.1
|
|
51
55
|
gemfile: gemfiles/opal_0.10_react_15.gemfile
|
|
56
|
+
- rvm: 2.1
|
|
57
|
+
env: PHANTOMJS_VERSION=2.1.1
|
|
58
|
+
gemfile: gemfiles/opal_master_react_15.gemfile
|
|
59
|
+
allow_failures:
|
|
60
|
+
- rvm: 2.1
|
|
61
|
+
env: PHANTOMJS_VERSION=2.1.1
|
|
62
|
+
gemfile: gemfiles/opal_master_react_15.gemfile
|
data/Appraisals
CHANGED
|
@@ -13,9 +13,19 @@ opal_rails_versions_map = {
|
|
|
13
13
|
opal_versions.each do |opal_v|
|
|
14
14
|
react_versions_map.each do |react_v, react_rails_v|
|
|
15
15
|
appraise "opal-#{opal_v}-react-#{react_v}" do
|
|
16
|
+
ruby ">= 1.9.3"
|
|
16
17
|
gem 'opal', "~> #{opal_v}.0"
|
|
17
18
|
gem 'opal-rails', opal_rails_versions_map[opal_v]
|
|
18
19
|
gem 'react-rails', react_rails_v, require: false
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
22
|
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
appraise "opal-master-react-15" do
|
|
26
|
+
ruby '>= 2.0.0'
|
|
27
|
+
gem 'opal', git: 'https://github.com/opal/opal.git'
|
|
28
|
+
gem "opal-sprockets", git: 'https://github.com/opal/opal-sprockets.git'
|
|
29
|
+
gem 'opal-rails', '~> 0.9.0'
|
|
30
|
+
gem 'react-rails', '~> 1.10.0', require: false
|
|
31
|
+
end
|
data/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,37 @@ Whitespace conventions:
|
|
|
18
18
|
- 1 spaces before normal text
|
|
19
19
|
-->
|
|
20
20
|
|
|
21
|
+
## [0.12.0] - Unreleased
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- `React::Server` is provided as a module wrapping the original `ReactDOMServer` API, require `react/server` to use it. (#186)
|
|
26
|
+
- `React::Config` is introduced, `environment` is the only config option provided for now. See [#204](https://github.com/ruby-hyperloop/hyper-react/issues/204) for usage details.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- State syntax is now consistent with Hyperloop::Store, old syntax is deprecated. (#209, #97)
|
|
31
|
+
|
|
32
|
+
### Deprecated
|
|
33
|
+
|
|
34
|
+
- Current ref callback behavior is deprecated. Require `"react/ref_callback"` to get the updated behavior. (#188)
|
|
35
|
+
- `React.render_to_string` & `React.render_to_static_markup` is deprecated, use `React::Server.render_to_string` & `React::Server.render_to_static_markup` instead. (#186)
|
|
36
|
+
- `react/react-source` is deprecated, use `react/react-source-browser` or `react/react-source-server` instead. For most usecase, `react/react-source-browser` is sufficient. If you are using the built-in server side rendering feature, the actual `ReactDOMServer` is already provided by the `react-rails` gem. Therefore, unless you are building a custom server side rendering mechanism, it's not suggested to use `react/react-source-server` in browser code. (#186)
|
|
37
|
+
|
|
38
|
+
### Removed
|
|
39
|
+
|
|
40
|
+
- `react-latest` & `react-v1x` is removed. Use `react/react-source-browser` or `react/react-source-server` instead.
|
|
41
|
+
- Support for Ruby < 2.0 is removed. (#201)
|
|
42
|
+
|
|
43
|
+
### Fixed
|
|
44
|
+
|
|
45
|
+
- [NativeLibrary] Passing native JS object as props will raise exception. (#195)
|
|
46
|
+
- Returns better error message if result of rendering block is not suitable (#207)
|
|
47
|
+
- Batch all state changes and execute *after* rendering cycle (#206, #178) (Code is now moved to Hyper::Store)
|
|
48
|
+
You can revert to the old behavior by defining the `React::State::ALWAYS_UPDATE_STATE_AFTER_RENDER = false`
|
|
49
|
+
- Memory Leak in render context fixed (#192)
|
|
50
|
+
|
|
51
|
+
|
|
21
52
|
## [0.11.0] - 2016-12-13
|
|
22
53
|
|
|
23
54
|
### Changed
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -48,6 +48,13 @@ You can simply include `React::Component` to get the power of a complete DSL to
|
|
|
48
48
|
As events occur, components update their state, which causes them to rerender, and perhaps pass new parameters to lower level components, thus causing them to rerender.
|
|
49
49
|
|
|
50
50
|
```ruby
|
|
51
|
+
require 'opal'
|
|
52
|
+
require 'browser/interval'
|
|
53
|
+
require 'opal-jquery'
|
|
54
|
+
require 'react/react-source'
|
|
55
|
+
require 'hyper-react'
|
|
56
|
+
require 'react/top_level_render'
|
|
57
|
+
|
|
51
58
|
class HelloWorld < React::Component::Base
|
|
52
59
|
param :time, type: Time
|
|
53
60
|
render do
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.10.0"
|
|
6
10
|
gem "opal-rails", "~> 0.9.0"
|
|
7
11
|
gem "react-rails", "~> 1.3.3", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.10.0"
|
|
6
10
|
gem "opal-rails", "~> 0.9.0"
|
|
7
11
|
gem "react-rails", "~> 1.6.2", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.10.0"
|
|
6
10
|
gem "opal-rails", "~> 0.9.0"
|
|
7
11
|
gem "react-rails", "~> 1.10.0", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.8.0"
|
|
6
10
|
gem "opal-rails", "~> 0.8.1"
|
|
7
11
|
gem "react-rails", "~> 1.3.3", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.8.0"
|
|
6
10
|
gem "opal-rails", "~> 0.8.1"
|
|
7
11
|
gem "react-rails", "~> 1.6.2", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.8.0"
|
|
6
10
|
gem "opal-rails", "~> 0.8.1"
|
|
7
11
|
gem "react-rails", "~> 1.10.0", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.9.0"
|
|
6
10
|
gem "opal-rails", "~> 0.9.0"
|
|
7
11
|
gem "react-rails", "~> 1.3.3", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.9.0"
|
|
6
10
|
gem "opal-rails", "~> 0.9.0"
|
|
7
11
|
gem "react-rails", "~> 1.6.2", :require => false
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
ruby ">= 1.9.3"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
5
9
|
gem "opal", "~> 0.9.0"
|
|
6
10
|
gem "opal-rails", "~> 0.9.0"
|
|
7
11
|
gem "react-rails", "~> 1.10.0", :require => false
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
ruby ">= 2.0.0"
|
|
6
|
+
|
|
7
|
+
gem "hyper-store", :path => "../../hyper-store"
|
|
8
|
+
gem "hyperloop-config", :path => "../../hyperloop-config"
|
|
9
|
+
gem "opal", :git => "https://github.com/opal/opal.git"
|
|
10
|
+
gem "opal-sprockets", :git => "https://github.com/opal/opal-sprockets.git"
|
|
11
|
+
gem "opal-rails", "~> 0.9.0"
|
|
12
|
+
gem "react-rails", "~> 1.10.0", :require => false
|
|
13
|
+
|
|
14
|
+
group :development do
|
|
15
|
+
gem "appraisal"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
gemspec :path => "../"
|
data/hyper-react.gemspec
CHANGED
|
@@ -21,6 +21,8 @@ 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_dependency 'hyper-store'
|
|
25
|
+
s.add_dependency 'hyperloop-config'
|
|
24
26
|
s.add_development_dependency 'rake', '< 11.0'
|
|
25
27
|
s.add_development_dependency 'rspec-rails', '3.3.3'
|
|
26
28
|
s.add_development_dependency 'timecop'
|
|
@@ -32,6 +34,8 @@ Gem::Specification.new do |s|
|
|
|
32
34
|
s.add_development_dependency 'rails', '4.2.4'
|
|
33
35
|
s.add_development_dependency 'mime-types', '< 3'
|
|
34
36
|
s.add_development_dependency 'opal-rails'
|
|
37
|
+
s.add_development_dependency 'nokogiri', '< 1.7'
|
|
38
|
+
s.add_development_dependency 'rubocop'
|
|
35
39
|
if RUBY_PLATFORM == 'java'
|
|
36
40
|
s.add_development_dependency 'jdbc-sqlite3'
|
|
37
41
|
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
|
data/lib/hyper-react.rb
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
require 'hyperloop-config'
|
|
2
|
+
Hyperloop.require_gem 'react/react-source-browser'
|
|
3
|
+
Hyperloop.require_gem 'react/react-source-server', server_only: true
|
|
4
|
+
Hyperloop.require_gem 'opal-jquery', client_only: true
|
|
5
|
+
Hyperloop.require_gem 'browser/delay', client_only: true
|
|
6
|
+
Hyperloop.require_gem 'react_ujs', client_only: true
|
|
2
7
|
|
|
3
8
|
if RUBY_ENGINE == 'opal'
|
|
9
|
+
|
|
10
|
+
module Hyperloop
|
|
11
|
+
class Component
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
4
15
|
if `Opal.global.React === undefined || Opal.global.React.version === undefined`
|
|
5
16
|
raise [
|
|
6
17
|
"No React.js Available",
|
|
@@ -8,7 +19,7 @@ if RUBY_ENGINE == 'opal'
|
|
|
8
19
|
"A global `React` must be defined before requiring 'hyper-react'",
|
|
9
20
|
"",
|
|
10
21
|
"To USE THE BUILT-IN SOURCE: ",
|
|
11
|
-
" add 'require \"react/react-source\"' immediately before the 'require \"hyper-react\" directive.",
|
|
22
|
+
" add 'require \"react/react-source-browser\"' immediately before the 'require \"hyper-react\" directive.",
|
|
12
23
|
"IF USING WEBPACK:",
|
|
13
24
|
" add 'react' to your webpack manifest."
|
|
14
25
|
].join("\n")
|
|
@@ -32,7 +43,17 @@ if RUBY_ENGINE == 'opal'
|
|
|
32
43
|
require 'reactive-ruby/isomorphic_helpers'
|
|
33
44
|
require 'rails-helpers/top_level_rails_component'
|
|
34
45
|
require 'reactive-ruby/version'
|
|
35
|
-
|
|
46
|
+
module Hyperloop
|
|
47
|
+
class Component
|
|
48
|
+
def self.inherited(child)
|
|
49
|
+
child.include(Mixin)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
React::Component.deprecation_warning(
|
|
54
|
+
'components.rb',
|
|
55
|
+
"Requiring 'hyper-react' is deprecated. Use gem 'hyper-component', and require 'hyper-component' instead."
|
|
56
|
+
) unless defined? Hyperloop::Component::VERSION
|
|
36
57
|
else
|
|
37
58
|
require 'opal'
|
|
38
59
|
# rubocop:disable Lint/HandleExceptions
|
|
@@ -48,6 +69,5 @@ else
|
|
|
48
69
|
require 'reactive-ruby/serializers'
|
|
49
70
|
|
|
50
71
|
Opal.append_path File.expand_path('../', __FILE__).untaint
|
|
51
|
-
Opal.append_path File.expand_path('../sources/', __FILE__).untaint
|
|
52
72
|
require "react/react-source"
|
|
53
73
|
end
|
data/lib/react/api.rb
CHANGED
|
@@ -142,6 +142,16 @@ module React
|
|
|
142
142
|
props["className"] = value
|
|
143
143
|
elsif ["style", "dangerously_set_inner_HTML"].include? key
|
|
144
144
|
props[lower_camelize(key)] = value.to_n
|
|
145
|
+
elsif key == 'ref' && value.is_a?(Proc)
|
|
146
|
+
unless React.const_defined?(:RefsCallbackExtension)
|
|
147
|
+
%x{
|
|
148
|
+
console.error(
|
|
149
|
+
"Warning: Using deprecated behavior of ref callback,",
|
|
150
|
+
"require \"react/ref_callback\" to get the correct behavior."
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
end
|
|
154
|
+
props[key] = value
|
|
145
155
|
elsif React::HASH_ATTRIBUTES.include?(key) && value.is_a?(Hash)
|
|
146
156
|
value.each { |k, v| props["#{key}-#{k.tr('_', '-')}"] = v.to_n }
|
|
147
157
|
else
|
data/lib/react/component.rb
CHANGED
|
@@ -3,137 +3,166 @@ require 'react/ext/hash'
|
|
|
3
3
|
require 'active_support/core_ext/class/attribute'
|
|
4
4
|
require 'react/callbacks'
|
|
5
5
|
require 'react/rendering_context'
|
|
6
|
-
require '
|
|
7
|
-
require 'react/
|
|
6
|
+
require 'hyper-store'
|
|
7
|
+
require 'react/state_wrapper'
|
|
8
8
|
require 'react/component/api'
|
|
9
9
|
require 'react/component/class_methods'
|
|
10
10
|
require 'react/component/props_wrapper'
|
|
11
11
|
require 'native'
|
|
12
12
|
|
|
13
|
-
module
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
module Hyperloop
|
|
14
|
+
class Component
|
|
15
|
+
module Mixin
|
|
16
|
+
def self.included(base)
|
|
17
|
+
base.include(Store::Mixin)
|
|
18
|
+
base.include(React::Component::API)
|
|
19
|
+
base.include(React::Component::Callbacks)
|
|
20
|
+
base.include(React::Component::Tags)
|
|
21
|
+
base.include(React::Component::DslInstanceMethods)
|
|
22
|
+
base.include(React::Component::ShouldComponentUpdate)
|
|
23
|
+
base.class_eval do
|
|
24
|
+
class_attribute :initial_state
|
|
25
|
+
define_callback :before_mount
|
|
26
|
+
define_callback :after_mount
|
|
27
|
+
define_callback :before_receive_props
|
|
28
|
+
define_callback :before_update
|
|
29
|
+
define_callback :after_update
|
|
30
|
+
define_callback :before_unmount
|
|
31
|
+
end
|
|
32
|
+
base.extend(React::Component::ClassMethods)
|
|
33
|
+
end
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
message = "Warning: Deprecated feature used in #{name}. #{message}"
|
|
36
|
-
unless @deprecation_messages.include? message
|
|
37
|
-
@deprecation_messages << message
|
|
38
|
-
IsomorphicHelpers.log message, :warning
|
|
35
|
+
def self.deprecation_warning(message)
|
|
36
|
+
React::Component.deprecation_warning(name, message)
|
|
39
37
|
end
|
|
40
|
-
end
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
def deprecation_warning(message)
|
|
40
|
+
React::Component.deprecation_warning(self.class.name, message)
|
|
41
|
+
end
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
def initialize(native_element)
|
|
44
|
+
@native = native_element
|
|
45
|
+
init_store
|
|
46
|
+
end
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
State.initialize_states(self, initial_state)
|
|
54
|
-
State.set_state_context_to(self) { run_callback(:before_mount) }
|
|
55
|
-
rescue Exception => e
|
|
56
|
-
self.class.process_exception(e, self)
|
|
57
|
-
end
|
|
48
|
+
def emit(event_name, *args)
|
|
49
|
+
params["_on#{event_name.to_s.event_camelize}"].call(*args)
|
|
50
|
+
end
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
State.
|
|
52
|
+
def component_will_mount
|
|
53
|
+
React::IsomorphicHelpers.load_context(true) if React::IsomorphicHelpers.on_opal_client?
|
|
54
|
+
# set_state! initial_state if initial_state
|
|
55
|
+
# State.initialize_states(self, initial_state)
|
|
56
|
+
React::State.set_state_context_to(self) { run_callback(:before_mount) }
|
|
57
|
+
rescue Exception => e
|
|
58
|
+
self.class.process_exception(e, self)
|
|
63
59
|
end
|
|
64
|
-
rescue Exception => e
|
|
65
|
-
self.class.process_exception(e, self)
|
|
66
|
-
end
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
def component_did_mount
|
|
62
|
+
React::State.set_state_context_to(self) do
|
|
63
|
+
run_callback(:after_mount)
|
|
64
|
+
React::State.update_states_to_observe
|
|
65
|
+
end
|
|
66
|
+
rescue Exception => e
|
|
67
|
+
self.class.process_exception(e, self)
|
|
68
|
+
end
|
|
75
69
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
def component_will_receive_props(next_props)
|
|
71
|
+
# need to rethink how this works in opal-react, or if its actually that useful within the react.rb environment
|
|
72
|
+
# for now we are just using it to clear processed_params
|
|
73
|
+
React::State.set_state_context_to(self) { self.run_callback(:before_receive_props, Hash.new(next_props)) }
|
|
74
|
+
rescue Exception => e
|
|
75
|
+
self.class.process_exception(e, self)
|
|
76
|
+
end
|
|
81
77
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
def component_will_update(next_props, next_state)
|
|
79
|
+
React::State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
|
|
80
|
+
rescue Exception => e
|
|
81
|
+
self.class.process_exception(e, self)
|
|
86
82
|
end
|
|
87
|
-
rescue Exception => e
|
|
88
|
-
self.class.process_exception(e, self)
|
|
89
|
-
end
|
|
90
83
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
def component_did_update(prev_props, prev_state)
|
|
85
|
+
React::State.set_state_context_to(self) do
|
|
86
|
+
self.run_callback(:after_update, Hash.new(prev_props), Hash.new(prev_state))
|
|
87
|
+
React::State.update_states_to_observe
|
|
88
|
+
end
|
|
89
|
+
rescue Exception => e
|
|
90
|
+
self.class.process_exception(e, self)
|
|
95
91
|
end
|
|
96
|
-
rescue Exception => e
|
|
97
|
-
self.class.process_exception(e, self)
|
|
98
|
-
end
|
|
99
92
|
|
|
100
|
-
|
|
93
|
+
def component_will_unmount
|
|
94
|
+
React::State.set_state_context_to(self) do
|
|
95
|
+
self.run_callback(:before_unmount)
|
|
96
|
+
React::State.remove
|
|
97
|
+
end
|
|
98
|
+
rescue Exception => e
|
|
99
|
+
self.class.process_exception(e, self)
|
|
100
|
+
end
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
attr_reader :waiting_on_resources
|
|
103
|
+
|
|
104
|
+
def update_react_js_state(object, name, value)
|
|
105
|
+
if object
|
|
106
|
+
name = "#{object.class}.#{name}" unless object == self
|
|
107
|
+
set_state(
|
|
108
|
+
'***_state_updated_at-***' => Time.now.to_f,
|
|
109
|
+
name => value
|
|
110
|
+
)
|
|
111
|
+
else
|
|
112
|
+
set_state name => value
|
|
113
|
+
end
|
|
111
114
|
end
|
|
112
|
-
end
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
116
|
+
def render
|
|
117
|
+
raise 'no render defined'
|
|
118
|
+
end unless method_defined?(:render)
|
|
119
|
+
|
|
120
|
+
def _render_wrapper
|
|
121
|
+
React::State.set_state_context_to(self, true) do
|
|
122
|
+
element = React::RenderingContext.render(nil) { render || '' }
|
|
123
|
+
@waiting_on_resources =
|
|
124
|
+
element.waiting_on_resources if element.respond_to? :waiting_on_resources
|
|
125
|
+
element
|
|
126
|
+
end
|
|
127
|
+
# rubocop:disable Lint/RescueException # we want to catch all exceptions regardless
|
|
128
|
+
rescue Exception => e
|
|
129
|
+
# rubocop:enable Lint/RescueException
|
|
130
|
+
self.class.process_exception(e, self)
|
|
131
|
+
end
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
def watch(value, &on_change)
|
|
134
|
+
Observable.new(value, on_change)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def define_state(*args, &block)
|
|
138
|
+
React::State.initialize_states(self, self.class.define_state(*args, &block))
|
|
139
|
+
end
|
|
133
140
|
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
134
143
|
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
module React
|
|
145
|
+
module Component
|
|
146
|
+
def self.included(base)
|
|
147
|
+
# note this is turned off during old style testing: See the spec_helper
|
|
148
|
+
deprecation_warning base, "The module name React::Component has been deprecated. Use Hyperloop::Component::Mixin instead."
|
|
149
|
+
base.include Hyperloop::Component::Mixin
|
|
150
|
+
end
|
|
151
|
+
def self.deprecation_warning(name, message)
|
|
152
|
+
@deprecation_messages ||= []
|
|
153
|
+
message = "Warning: Deprecated feature used in #{name}. #{message}"
|
|
154
|
+
unless @deprecation_messages.include? message
|
|
155
|
+
@deprecation_messages << message
|
|
156
|
+
React::IsomorphicHelpers.log message, :warning
|
|
157
|
+
end
|
|
137
158
|
end
|
|
138
159
|
end
|
|
160
|
+
module ComponentNoNotice
|
|
161
|
+
def self.included(base)
|
|
162
|
+
base.include Hyperloop::Component::Mixin
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
module React
|
|
139
168
|
end
|