hyper-react 0.12.7 → 0.99.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 (129) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +48 -34
  3. data/CODE_OF_CONDUCT.md +49 -0
  4. data/Gemfile +5 -6
  5. data/README.md +47 -98
  6. data/Rakefile +6 -28
  7. data/hyper-react.gemspec +36 -43
  8. data/lib/hyper-react.rb +4 -73
  9. data/lib/react/version.rb +3 -0
  10. metadata +91 -249
  11. data/.codeclimate.yml +0 -27
  12. data/.rubocop.yml +0 -1159
  13. data/.travis.yml +0 -62
  14. data/Appraisals +0 -31
  15. data/CHANGELOG.md +0 -143
  16. data/LICENSE +0 -19
  17. data/UPGRADING.md +0 -24
  18. data/component-name-lookup.md +0 -145
  19. data/config.ru +0 -26
  20. data/gemfiles/opal_0.10_react_13.gemfile +0 -15
  21. data/gemfiles/opal_0.10_react_14.gemfile +0 -15
  22. data/gemfiles/opal_0.10_react_15.gemfile +0 -15
  23. data/gemfiles/opal_0.8_react_13.gemfile +0 -15
  24. data/gemfiles/opal_0.8_react_14.gemfile +0 -15
  25. data/gemfiles/opal_0.8_react_15.gemfile +0 -15
  26. data/gemfiles/opal_0.9_react_13.gemfile +0 -15
  27. data/gemfiles/opal_0.9_react_14.gemfile +0 -15
  28. data/gemfiles/opal_0.9_react_15.gemfile +0 -15
  29. data/gemfiles/opal_master_react_15.gemfile +0 -16
  30. data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
  31. data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +0 -2
  32. data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +0 -6
  33. data/lib/generators/reactive_ruby/test_app/templates/script/rails +0 -5
  34. data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +0 -13
  35. data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
  36. data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
  37. data/lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb +0 -0
  38. data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +0 -111
  39. data/lib/rails-helpers/top_level_rails_component.rb +0 -54
  40. data/lib/react-sources/react-server.js +0 -2
  41. data/lib/react/api.rb +0 -173
  42. data/lib/react/callbacks.rb +0 -41
  43. data/lib/react/children.rb +0 -30
  44. data/lib/react/component.rb +0 -168
  45. data/lib/react/component/api.rb +0 -50
  46. data/lib/react/component/base.rb +0 -13
  47. data/lib/react/component/class_methods.rb +0 -189
  48. data/lib/react/component/dsl_instance_methods.rb +0 -23
  49. data/lib/react/component/params.rb +0 -6
  50. data/lib/react/component/props_wrapper.rb +0 -78
  51. data/lib/react/component/should_component_update.rb +0 -94
  52. data/lib/react/component/tags.rb +0 -129
  53. data/lib/react/config.rb +0 -5
  54. data/lib/react/config/client.rb.erb +0 -19
  55. data/lib/react/config/server.rb +0 -23
  56. data/lib/react/element.rb +0 -169
  57. data/lib/react/event.rb +0 -76
  58. data/lib/react/ext/hash.rb +0 -9
  59. data/lib/react/ext/opal-jquery/element.rb +0 -26
  60. data/lib/react/ext/string.rb +0 -8
  61. data/lib/react/hash.rb +0 -13
  62. data/lib/react/native_library.rb +0 -87
  63. data/lib/react/object.rb +0 -15
  64. data/lib/react/react-source-browser.rb +0 -3
  65. data/lib/react/react-source-server.rb +0 -3
  66. data/lib/react/react-source.rb +0 -20
  67. data/lib/react/ref_callback.rb +0 -31
  68. data/lib/react/rendering_context.rb +0 -144
  69. data/lib/react/server.rb +0 -23
  70. data/lib/react/state_wrapper.rb +0 -23
  71. data/lib/react/test.rb +0 -16
  72. data/lib/react/test/dsl.rb +0 -17
  73. data/lib/react/test/matchers/render_html_matcher.rb +0 -56
  74. data/lib/react/test/rspec.rb +0 -15
  75. data/lib/react/test/session.rb +0 -37
  76. data/lib/react/test/utils.rb +0 -25
  77. data/lib/react/top_level.rb +0 -118
  78. data/lib/react/top_level_render.rb +0 -29
  79. data/lib/react/validator.rb +0 -136
  80. data/lib/reactive-ruby/component_loader.rb +0 -50
  81. data/lib/reactive-ruby/isomorphic_helpers.rb +0 -212
  82. data/lib/reactive-ruby/rails.rb +0 -7
  83. data/lib/reactive-ruby/rails/component_mount.rb +0 -46
  84. data/lib/reactive-ruby/rails/controller_helper.rb +0 -15
  85. data/lib/reactive-ruby/rails/railtie.rb +0 -33
  86. data/lib/reactive-ruby/serializers.rb +0 -15
  87. data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +0 -42
  88. data/lib/reactive-ruby/version.rb +0 -3
  89. data/lib/reactrb/auto-import.rb +0 -27
  90. data/lib/reactrb/deep-compare.rb +0 -24
  91. data/lib/reactrb/new-event-name-convention.rb +0 -11
  92. data/logo1.png +0 -0
  93. data/logo2.png +0 -0
  94. data/logo3.png +0 -0
  95. data/path_release_steps.md +0 -9
  96. data/spec/controller_helper_spec.rb +0 -34
  97. data/spec/index.html.erb +0 -11
  98. data/spec/react/callbacks_spec.rb +0 -138
  99. data/spec/react/children_spec.rb +0 -76
  100. data/spec/react/component/base_spec.rb +0 -32
  101. data/spec/react/component_spec.rb +0 -884
  102. data/spec/react/dsl_spec.rb +0 -303
  103. data/spec/react/element_spec.rb +0 -136
  104. data/spec/react/event_spec.rb +0 -24
  105. data/spec/react/native_library_spec.rb +0 -322
  106. data/spec/react/observable_spec.rb +0 -42
  107. data/spec/react/opal_jquery_extensions_spec.rb +0 -68
  108. data/spec/react/param_declaration_spec.rb +0 -269
  109. data/spec/react/react_spec.rb +0 -215
  110. data/spec/react/refs_callback_spec.rb +0 -56
  111. data/spec/react/server_spec.rb +0 -25
  112. data/spec/react/state_spec.rb +0 -55
  113. data/spec/react/test/dsl_spec.rb +0 -43
  114. data/spec/react/test/matchers/render_html_matcher_spec.rb +0 -83
  115. data/spec/react/test/rspec_spec.rb +0 -62
  116. data/spec/react/test/session_spec.rb +0 -88
  117. data/spec/react/test/utils_spec.rb +0 -28
  118. data/spec/react/top_level_component_spec.rb +0 -101
  119. data/spec/react/tutorial/tutorial_spec.rb +0 -36
  120. data/spec/react/validator_spec.rb +0 -124
  121. data/spec/reactive-ruby/component_loader_spec.rb +0 -77
  122. data/spec/reactive-ruby/isomorphic_helpers_spec.rb +0 -160
  123. data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +0 -10
  124. data/spec/reactive-ruby/rails/component_mount_spec.rb +0 -66
  125. data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +0 -35
  126. data/spec/spec_helper.rb +0 -149
  127. data/spec/support/react/spec_helpers.rb +0 -44
  128. data/spec/vendor/es5-shim.min.js +0 -6
  129. data/spec/vendor/jquery-2.2.4.min.js +0 -4
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.10.0"
8
- gem "opal-rails", "~> 0.9.0"
9
- gem "react-rails", "~> 1.3.3", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.10.0"
8
- gem "opal-rails", "~> 0.9.0"
9
- gem "react-rails", "~> 1.6.2", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.10.0"
8
- gem "opal-rails", "~> 0.9.0"
9
- gem "react-rails", "~> 1.10.0", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.8.0"
8
- gem "opal-rails", "~> 0.8.1"
9
- gem "react-rails", "~> 1.3.3", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.8.0"
8
- gem "opal-rails", "~> 0.8.1"
9
- gem "react-rails", "~> 1.6.2", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.8.0"
8
- gem "opal-rails", "~> 0.8.1"
9
- gem "react-rails", "~> 1.10.0", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.9.0"
8
- gem "opal-rails", "~> 0.9.0"
9
- gem "react-rails", "~> 1.3.3", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.9.0"
8
- gem "opal-rails", "~> 0.9.0"
9
- gem "react-rails", "~> 1.6.2", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 1.9.3"
6
-
7
- gem "opal", "~> 0.9.0"
8
- gem "opal-rails", "~> 0.9.0"
9
- gem "react-rails", "~> 1.10.0", :require => false
10
-
11
- group :development do
12
- gem "appraisal"
13
- end
14
-
15
- gemspec :path => "../"
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 2.0.0"
6
-
7
- gem "opal", :git => "https://github.com/opal/opal.git"
8
- gem "opal-sprockets", :git => "https://github.com/opal/opal-sprockets.git"
9
- gem "opal-rails", "~> 0.9.0"
10
- gem "react-rails", "~> 1.10.0", :require => false
11
-
12
- group :development do
13
- gem "appraisal"
14
- end
15
-
16
- gemspec :path => "../"
@@ -1,3 +0,0 @@
1
- require 'opal'
2
- require 'hyper-react'
3
- require_tree './components'
@@ -1,2 +0,0 @@
1
- require 'components'
2
- require 'react_ujs'
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path("<%= gemfile_path %>", __FILE__)
3
-
4
- ENV['BUNDLE_GEMFILE'] = gemfile
5
- require 'bundler'
6
- Bundler.setup
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- APP_PATH = File.expand_path('../../config/application', __FILE__)
4
- require File.expand_path('../../config/boot', __FILE__)
5
- require 'rails/commands'
@@ -1,13 +0,0 @@
1
- <% if defined? application_definition %>
2
- require 'rails/all'
3
- require File.expand_path('../boot', __FILE__)
4
-
5
- # Require the gems listed in Gemfile, including any gems
6
- # you've limited to :test, :development, or :production.
7
- Bundler.require(*Rails.groups(assets: %w(development test)))
8
-
9
- require 'opal-rails'
10
- require 'hyper-react'
11
-
12
- <%= application_definition %>
13
- <% end %>
@@ -1,11 +0,0 @@
1
- module Components
2
- class HelloWorld
3
- include React::Component
4
-
5
- def render
6
- div do
7
- "Hello, World!".span
8
- end
9
- end
10
- end
11
- end
@@ -1,14 +0,0 @@
1
- module Components
2
- class Todo
3
- include React::Component
4
- export_component
5
-
6
- params do
7
- requires :todo
8
- end
9
-
10
- def render
11
- li { "#{params[:todo]}" }
12
- end
13
- end
14
- end
@@ -1,111 +0,0 @@
1
- require 'rails/generators/rails/app/app_generator'
2
-
3
- module ReactiveRuby
4
- class TestAppGenerator < ::Rails::Generators::Base
5
- def self.source_paths
6
- paths = self.superclass.source_paths
7
- paths << File.expand_path('../templates', __FILE__)
8
- paths.flatten
9
- end
10
-
11
- def remove_existing_app
12
- remove_dir(test_app_path) if File.directory?(test_app_path)
13
- end
14
-
15
- def generate_test_app
16
- opts = options.dup
17
- opts[:database] = 'sqlite3' if opts[:database].blank?
18
- opts[:force] = true
19
- opts[:skip_bundle] = true
20
-
21
- puts "Generating Test Rails Application..."
22
- invoke ::Rails::Generators::AppGenerator,
23
- [ File.expand_path(test_app_path, destination_root) ], opts
24
- end
25
-
26
- def configure_test_app
27
- template 'boot.rb.erb', "#{test_app_path}/config/boot.rb", force: true
28
- template 'test_application.rb.erb', "#{test_app_path}/config/application.rb", force: true
29
- template 'assets/javascripts/test_application.rb',
30
- "#{test_app_path}/app/assets/javascripts/application.rb", force: true
31
- template 'assets/javascripts/components.rb',
32
- "#{test_app_path}/app/views/components.rb", force: true
33
- template 'views/components/hello_world.rb',
34
- "#{test_app_path}/app/views/components/hello_world.rb", force: true
35
- template 'views/components/todo.rb',
36
- "#{test_app_path}/app/views/components/todo.rb", force: true
37
- template 'views/layouts/test_layout.html.erb',
38
- "#{test_app_path}/app/views/layouts/test_layout.html.erb", force: true
39
- template 'views/layouts/test_layout.html.erb',
40
- "#{test_app_path}/app/views/layouts/explicit_layout.html.erb", force: true
41
- end
42
-
43
- def clean_superfluous_files
44
- inside test_app_path do
45
- remove_file '.gitignore'
46
- remove_file 'doc'
47
- remove_file 'Gemfile'
48
- remove_file 'lib/tasks'
49
- remove_file 'app/assets/images/rails.png'
50
- remove_file 'app/assets/javascripts/application.js'
51
- remove_file 'public/index.html'
52
- remove_file 'public/robots.txt'
53
- remove_file 'README.rdoc'
54
- remove_file 'test'
55
- remove_file 'vendor'
56
- remove_file 'spec'
57
- end
58
- end
59
-
60
- def configure_opal_rspec
61
- inject_into_file "#{test_app_path}/config/application.rb",
62
- after: /class Application < Rails::Application/, verbose: true do
63
- %Q[
64
- config.opal.method_missing = true
65
- config.opal.optimized_operators = true
66
- config.opal.arity_check = false
67
- config.opal.const_missing = true
68
- config.opal.dynamic_require_severity = :ignore
69
- config.opal.enable_specs = true
70
- config.opal.spec_location = 'spec-opal'
71
- config.hyperloop.auto_config = false
72
-
73
- ]
74
- end
75
- end
76
-
77
- protected
78
-
79
- def application_definition
80
- @application_definition ||= begin
81
- test_application_contents
82
- end
83
- end
84
- alias :store_application_definition! :application_definition
85
-
86
- private
87
-
88
- def test_app_path
89
- 'spec/test_app'
90
- end
91
-
92
- def test_application_path
93
- File.expand_path("#{test_app_path}/config/application.rb",
94
- destination_root)
95
- end
96
-
97
- def test_application_contents
98
- return unless File.exists?(test_application_path) && !options[:pretend]
99
- contents = File.read(test_application_path)
100
- contents[(contents.index("module #{module_name}"))..-1]
101
- end
102
-
103
- def module_name
104
- 'TestApp'
105
- end
106
-
107
- def gemfile_path
108
- '../../../../Gemfile'
109
- end
110
- end
111
- end
@@ -1,54 +0,0 @@
1
- module React
2
- class TopLevelRailsComponent
3
- include Hyperloop::Component::Mixin
4
-
5
- def self.search_path
6
- @search_path ||= [Module]
7
- end
8
-
9
- export_component
10
-
11
- param :component_name
12
- param :controller
13
- param :render_params
14
-
15
- backtrace :off
16
-
17
- def render
18
- paths_searched = []
19
- if params.component_name.start_with? "::"
20
- paths_searched << params.component_name.gsub(/^\:\:/,"")
21
- component = params.component_name.gsub(/^\:\:/,"").split("::").inject(Module) { |scope, next_const| scope.const_get(next_const, false) } rescue nil
22
- return present component, params.render_params if component && component.method_defined?(:render)
23
- else
24
- self.class.search_path.each do |path|
25
- # try each path + params.controller + params.component_name
26
- paths_searched << "#{path.name + '::' unless path == Module}#{params.controller}::#{params.component_name}"
27
- component = "#{params.controller}::#{params.component_name}".split("::").inject(path) { |scope, next_const| scope.const_get(next_const, false) } rescue nil
28
- return present component, params.render_params if component && component.method_defined?(:render)
29
- end
30
- self.class.search_path.each do |path|
31
- # then try each path + params.component_name
32
- paths_searched << "#{path.name + '::' unless path == Module}#{params.component_name}"
33
- component = "#{params.component_name}".split("::").inject(path) { |scope, next_const| scope.const_get(next_const, false) } rescue nil
34
- return present component, params.render_params if component && component.method_defined?(:render)
35
- end
36
- end
37
- raise "Could not find component class '#{params.component_name}' for params.controller '#{params.controller}' in any component directory. Tried [#{paths_searched.join(", ")}]"
38
- end
39
- end
40
- end
41
-
42
- class Module
43
- def add_to_react_search_path(replace_search_path = nil)
44
- if replace_search_path
45
- React::TopLevelRailsComponent.search_path = [self]
46
- elsif !React::TopLevelRailsComponent.search_path.include? self
47
- React::TopLevelRailsComponent.search_path << self
48
- end
49
- end
50
- end
51
-
52
- module Components
53
- add_to_react_search_path
54
- end
@@ -1,2 +0,0 @@
1
- // A placeholder file to prevent file not found error of requireing
2
- // `react-server` in react/react-source
@@ -1,173 +0,0 @@
1
- require 'react/native_library'
2
-
3
- module React
4
- # Provides the internal mechanisms to interface between reactrb and native components
5
- # the code will attempt to create a js component wrapper on any rb class that has a
6
- # render (or possibly _render_wrapper) method. The mapping between rb and js components
7
- # is kept in the @@component_classes hash.
8
-
9
- # Also provides the mechanism to build react elements
10
-
11
- # TOOO - the code to deal with components should be moved to a module that will be included
12
- # in a class which will then create the JS component for that class. That module will then
13
- # be included in React::Component, but can be used by any class wanting to become a react
14
- # component (but without other DSL characteristics.)
15
- class API
16
- @@component_classes = {}
17
-
18
- def self.import_native_component(opal_class, native_class)
19
- opal_class.instance_variable_set("@native_import", true)
20
- @@component_classes[opal_class] = native_class
21
- end
22
-
23
- def self.eval_native_react_component(name)
24
- component = `eval(name)`
25
- raise "#{name} is not defined" if `#{component} === undefined`
26
- is_component_class = `#{component}.prototype !== undefined` &&
27
- (`!!#{component}.prototype.isReactComponent` ||
28
- `!!#{component}.prototype.render`)
29
- is_functional_component = `typeof #{component} === "function"`
30
- is_not_using_react_v13 = `!Opal.global.React.version.match(/0\.13/)`
31
- unless is_component_class || (is_not_using_react_v13 && is_functional_component)
32
- raise 'does not appear to be a native react component'
33
- end
34
- component
35
- end
36
-
37
- def self.native_react_component?(name = nil)
38
- return false unless name
39
- eval_native_react_component(name)
40
- rescue
41
- nil
42
- end
43
-
44
- def self.create_native_react_class(type)
45
- raise "Provided class should define `render` method" if !(type.method_defined? :render)
46
- render_fn = (type.method_defined? :_render_wrapper) ? :_render_wrapper : :render
47
- # this was hashing type.to_s, not sure why but .to_s does not work as it Foo::Bar::View.to_s just returns "View"
48
- @@component_classes[type] ||= %x{
49
- React.createClass({
50
- displayName: #{type.name},
51
- propTypes: #{type.respond_to?(:prop_types) ? type.prop_types.to_n : `{}`},
52
- getDefaultProps: function(){
53
- return #{type.respond_to?(:default_props) ? type.default_props.to_n : `{}`};
54
- },
55
- mixins: #{type.respond_to?(:native_mixins) ? type.native_mixins : `[]`},
56
- statics: #{type.respond_to?(:static_call_backs) ? type.static_call_backs.to_n : `{}`},
57
- componentWillMount: function() {
58
- var instance = this._getOpalInstance.apply(this);
59
- return #{`instance`.component_will_mount if type.method_defined? :component_will_mount};
60
- },
61
- componentDidMount: function() {
62
- var instance = this._getOpalInstance.apply(this);
63
- return #{`instance`.component_did_mount if type.method_defined? :component_did_mount};
64
- },
65
- componentWillReceiveProps: function(next_props) {
66
- var instance = this._getOpalInstance.apply(this);
67
- return #{`instance`.component_will_receive_props(Hash.new(`next_props`)) if type.method_defined? :component_will_receive_props};
68
- },
69
- shouldComponentUpdate: function(next_props, next_state) {
70
- var instance = this._getOpalInstance.apply(this);
71
- return #{`instance`.should_component_update?(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :should_component_update?};
72
- },
73
- componentWillUpdate: function(next_props, next_state) {
74
- var instance = this._getOpalInstance.apply(this);
75
- return #{`instance`.component_will_update(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :component_will_update};
76
- },
77
- componentDidUpdate: function(prev_props, prev_state) {
78
- var instance = this._getOpalInstance.apply(this);
79
- return #{`instance`.component_did_update(Hash.new(`prev_props`), Hash.new(`prev_state`)) if type.method_defined? :component_did_update};
80
- },
81
- componentWillUnmount: function() {
82
- var instance = this._getOpalInstance.apply(this);
83
- return #{`instance`.component_will_unmount if type.method_defined? :component_will_unmount};
84
- },
85
- _getOpalInstance: function() {
86
- if (this.__opalInstance == undefined) {
87
- var instance = #{type.new(`this`)};
88
- } else {
89
- var instance = this.__opalInstance;
90
- }
91
- this.__opalInstance = instance;
92
- return instance;
93
- },
94
- render: function() {
95
- var instance = this._getOpalInstance.apply(this);
96
- return #{`instance`.send(render_fn).to_n};
97
- }
98
- })
99
- }
100
- end
101
-
102
- def self.create_element(type, properties = {}, &block)
103
- params = []
104
-
105
- # Component Spec, Normal DOM, String or Native Component
106
- if @@component_classes[type]
107
- params << @@component_classes[type]
108
- elsif type.kind_of?(Class)
109
- params << create_native_react_class(type)
110
- elsif React::Component::Tags::HTML_TAGS.include?(type)
111
- params << type
112
- elsif type.is_a? String
113
- return React::Element.new(type)
114
- else
115
- raise "#{type} not implemented"
116
- end
117
-
118
- # Convert Passed in properties
119
- properties = convert_props(properties)
120
- params << properties.shallow_to_n
121
-
122
- # Children Nodes
123
- if block_given?
124
- [yield].flatten.each do |ele|
125
- params << ele.to_n
126
- end
127
- end
128
- React::Element.new(`React.createElement.apply(null, #{params})`, type, properties, block)
129
- end
130
-
131
- def self.clear_component_class_cache
132
- @@component_classes = {}
133
- end
134
-
135
- def self.convert_props(properties)
136
- raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash
137
- props = {}
138
- properties.map do |key, value|
139
- if key == "class_name" && value.is_a?(Hash)
140
- props[lower_camelize(key)] = `React.addons.classSet(#{value.to_n})`
141
- elsif key == "class"
142
- props["className"] = value
143
- elsif ["style", "dangerously_set_inner_HTML"].include? key
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
155
- elsif React::HASH_ATTRIBUTES.include?(key) && value.is_a?(Hash)
156
- value.each { |k, v| props["#{key}-#{k.tr('_', '-')}"] = v.to_n }
157
- else
158
- props[React.html_attr?(lower_camelize(key)) ? lower_camelize(key) : key] = value
159
- end
160
- end
161
- props
162
- end
163
-
164
- private
165
-
166
- def self.lower_camelize(snake_cased_word)
167
- words = snake_cased_word.split('_')
168
- result = [words.first]
169
- result.concat(words[1..-1].map {|word| word[0].upcase + word[1..-1] })
170
- result.join('')
171
- end
172
- end
173
- end