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.
- checksums.yaml +5 -5
- data/.gitignore +48 -34
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -6
- data/README.md +47 -98
- data/Rakefile +6 -28
- data/hyper-react.gemspec +36 -43
- data/lib/hyper-react.rb +4 -73
- data/lib/react/version.rb +3 -0
- metadata +91 -249
- data/.codeclimate.yml +0 -27
- data/.rubocop.yml +0 -1159
- data/.travis.yml +0 -62
- data/Appraisals +0 -31
- data/CHANGELOG.md +0 -143
- data/LICENSE +0 -19
- data/UPGRADING.md +0 -24
- data/component-name-lookup.md +0 -145
- data/config.ru +0 -26
- data/gemfiles/opal_0.10_react_13.gemfile +0 -15
- data/gemfiles/opal_0.10_react_14.gemfile +0 -15
- data/gemfiles/opal_0.10_react_15.gemfile +0 -15
- data/gemfiles/opal_0.8_react_13.gemfile +0 -15
- data/gemfiles/opal_0.8_react_14.gemfile +0 -15
- data/gemfiles/opal_0.8_react_15.gemfile +0 -15
- data/gemfiles/opal_0.9_react_13.gemfile +0 -15
- data/gemfiles/opal_0.9_react_14.gemfile +0 -15
- data/gemfiles/opal_0.9_react_15.gemfile +0 -15
- data/gemfiles/opal_master_react_15.gemfile +0 -16
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +0 -2
- data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +0 -6
- data/lib/generators/reactive_ruby/test_app/templates/script/rails +0 -5
- data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +0 -13
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
- data/lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb +0 -0
- data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +0 -111
- data/lib/rails-helpers/top_level_rails_component.rb +0 -54
- data/lib/react-sources/react-server.js +0 -2
- data/lib/react/api.rb +0 -173
- data/lib/react/callbacks.rb +0 -41
- data/lib/react/children.rb +0 -30
- data/lib/react/component.rb +0 -168
- data/lib/react/component/api.rb +0 -50
- data/lib/react/component/base.rb +0 -13
- data/lib/react/component/class_methods.rb +0 -189
- data/lib/react/component/dsl_instance_methods.rb +0 -23
- data/lib/react/component/params.rb +0 -6
- data/lib/react/component/props_wrapper.rb +0 -78
- data/lib/react/component/should_component_update.rb +0 -94
- data/lib/react/component/tags.rb +0 -129
- data/lib/react/config.rb +0 -5
- data/lib/react/config/client.rb.erb +0 -19
- data/lib/react/config/server.rb +0 -23
- data/lib/react/element.rb +0 -169
- data/lib/react/event.rb +0 -76
- data/lib/react/ext/hash.rb +0 -9
- data/lib/react/ext/opal-jquery/element.rb +0 -26
- data/lib/react/ext/string.rb +0 -8
- data/lib/react/hash.rb +0 -13
- data/lib/react/native_library.rb +0 -87
- data/lib/react/object.rb +0 -15
- data/lib/react/react-source-browser.rb +0 -3
- data/lib/react/react-source-server.rb +0 -3
- data/lib/react/react-source.rb +0 -20
- data/lib/react/ref_callback.rb +0 -31
- data/lib/react/rendering_context.rb +0 -144
- data/lib/react/server.rb +0 -23
- data/lib/react/state_wrapper.rb +0 -23
- data/lib/react/test.rb +0 -16
- data/lib/react/test/dsl.rb +0 -17
- data/lib/react/test/matchers/render_html_matcher.rb +0 -56
- data/lib/react/test/rspec.rb +0 -15
- data/lib/react/test/session.rb +0 -37
- data/lib/react/test/utils.rb +0 -25
- data/lib/react/top_level.rb +0 -118
- data/lib/react/top_level_render.rb +0 -29
- data/lib/react/validator.rb +0 -136
- data/lib/reactive-ruby/component_loader.rb +0 -50
- data/lib/reactive-ruby/isomorphic_helpers.rb +0 -212
- data/lib/reactive-ruby/rails.rb +0 -7
- data/lib/reactive-ruby/rails/component_mount.rb +0 -46
- data/lib/reactive-ruby/rails/controller_helper.rb +0 -15
- data/lib/reactive-ruby/rails/railtie.rb +0 -33
- data/lib/reactive-ruby/serializers.rb +0 -15
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +0 -42
- data/lib/reactive-ruby/version.rb +0 -3
- data/lib/reactrb/auto-import.rb +0 -27
- data/lib/reactrb/deep-compare.rb +0 -24
- data/lib/reactrb/new-event-name-convention.rb +0 -11
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +0 -9
- data/spec/controller_helper_spec.rb +0 -34
- data/spec/index.html.erb +0 -11
- data/spec/react/callbacks_spec.rb +0 -138
- data/spec/react/children_spec.rb +0 -76
- data/spec/react/component/base_spec.rb +0 -32
- data/spec/react/component_spec.rb +0 -884
- data/spec/react/dsl_spec.rb +0 -303
- data/spec/react/element_spec.rb +0 -136
- data/spec/react/event_spec.rb +0 -24
- data/spec/react/native_library_spec.rb +0 -322
- data/spec/react/observable_spec.rb +0 -42
- data/spec/react/opal_jquery_extensions_spec.rb +0 -68
- data/spec/react/param_declaration_spec.rb +0 -269
- data/spec/react/react_spec.rb +0 -215
- data/spec/react/refs_callback_spec.rb +0 -56
- data/spec/react/server_spec.rb +0 -25
- data/spec/react/state_spec.rb +0 -55
- data/spec/react/test/dsl_spec.rb +0 -43
- data/spec/react/test/matchers/render_html_matcher_spec.rb +0 -83
- data/spec/react/test/rspec_spec.rb +0 -62
- data/spec/react/test/session_spec.rb +0 -88
- data/spec/react/test/utils_spec.rb +0 -28
- data/spec/react/top_level_component_spec.rb +0 -101
- data/spec/react/tutorial/tutorial_spec.rb +0 -36
- data/spec/react/validator_spec.rb +0 -124
- data/spec/reactive-ruby/component_loader_spec.rb +0 -77
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +0 -160
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +0 -10
- data/spec/reactive-ruby/rails/component_mount_spec.rb +0 -66
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -149
- data/spec/support/react/spec_helpers.rb +0 -44
- data/spec/vendor/es5-shim.min.js +0 -6
- data/spec/vendor/jquery-2.2.4.min.js +0 -4
data/lib/react/callbacks.rb
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require 'hyperloop-config'
|
|
2
|
-
Hyperloop::Context
|
|
3
|
-
module React
|
|
4
|
-
module Callbacks
|
|
5
|
-
def self.included(base)
|
|
6
|
-
base.extend(ClassMethods)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def run_callback(name, *args)
|
|
10
|
-
self.class.callbacks_for(name).each do |callback|
|
|
11
|
-
if callback.is_a?(Proc)
|
|
12
|
-
instance_exec(*args, &callback)
|
|
13
|
-
else
|
|
14
|
-
send(callback, *args)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
module ClassMethods
|
|
20
|
-
def define_callback(callback_name)
|
|
21
|
-
wrapper_name = "_#{callback_name}_callbacks"
|
|
22
|
-
define_singleton_method(wrapper_name) do
|
|
23
|
-
Hyperloop::Context.set_var(self, "@#{wrapper_name}", force: true) { [] }
|
|
24
|
-
end
|
|
25
|
-
define_singleton_method(callback_name) do |*args, &block|
|
|
26
|
-
send(wrapper_name).concat(args)
|
|
27
|
-
send(wrapper_name).push(block) if block_given?
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def callbacks_for(callback_name)
|
|
32
|
-
wrapper_name = "_#{callback_name}_callbacks"
|
|
33
|
-
if superclass.respond_to? :callbacks_for
|
|
34
|
-
superclass.callbacks_for(callback_name)
|
|
35
|
-
else
|
|
36
|
-
[]
|
|
37
|
-
end + send(wrapper_name)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
data/lib/react/children.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
|
data/lib/react/component.rb
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
require 'react/ext/string'
|
|
2
|
-
require 'react/ext/hash'
|
|
3
|
-
require 'active_support/core_ext/class/attribute'
|
|
4
|
-
require 'react/callbacks'
|
|
5
|
-
require 'react/rendering_context'
|
|
6
|
-
require 'hyper-store'
|
|
7
|
-
require 'react/state_wrapper'
|
|
8
|
-
require 'react/component/api'
|
|
9
|
-
require 'react/component/class_methods'
|
|
10
|
-
require 'react/component/props_wrapper'
|
|
11
|
-
require 'native'
|
|
12
|
-
|
|
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
|
|
34
|
-
|
|
35
|
-
def self.deprecation_warning(message)
|
|
36
|
-
React::Component.deprecation_warning(name, message)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def deprecation_warning(message)
|
|
40
|
-
React::Component.deprecation_warning(self.class.name, message)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def initialize(native_element)
|
|
44
|
-
@native = native_element
|
|
45
|
-
init_store
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def emit(event_name, *args)
|
|
49
|
-
params["_on#{event_name.to_s.event_camelize}"].call(*args)
|
|
50
|
-
end
|
|
51
|
-
|
|
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)
|
|
59
|
-
end
|
|
60
|
-
|
|
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
|
|
69
|
-
|
|
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
|
|
77
|
-
|
|
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)
|
|
82
|
-
end
|
|
83
|
-
|
|
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)
|
|
91
|
-
end
|
|
92
|
-
|
|
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
|
-
|
|
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
|
|
114
|
-
end
|
|
115
|
-
|
|
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
|
|
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
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
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
|
|
158
|
-
end
|
|
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
|
|
168
|
-
end
|
data/lib/react/component/api.rb
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
module API
|
|
4
|
-
def dom_node
|
|
5
|
-
if !(`typeof ReactDOM === 'undefined' || typeof ReactDOM.findDOMNode === 'undefined'`)
|
|
6
|
-
`ReactDOM.findDOMNode(#{self}.native)` # v0.14.0
|
|
7
|
-
elsif !(`typeof React.findDOMNode === 'undefined'`)
|
|
8
|
-
`React.findDOMNode(#{self}.native)` # v0.13.0
|
|
9
|
-
else
|
|
10
|
-
`#{self}.native.getDOMNode` # v0.12.0
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def mounted?
|
|
15
|
-
`#{self}.native.isMounted()`
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def force_update!
|
|
19
|
-
`#{self}.native.forceUpdate()`
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def set_props(prop, &block)
|
|
23
|
-
set_or_replace_state_or_prop(prop, 'setProps', &block)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def set_props!(prop, &block)
|
|
27
|
-
set_or_replace_state_or_prop(prop, 'replaceProps', &block)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def set_state(state, &block)
|
|
31
|
-
set_or_replace_state_or_prop(state, 'setState', &block)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def set_state!(state, &block)
|
|
35
|
-
set_or_replace_state_or_prop(state, 'replaceState', &block)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def set_or_replace_state_or_prop(state_or_prop, method, &block)
|
|
41
|
-
raise "No native ReactComponent associated" unless @native
|
|
42
|
-
%x{
|
|
43
|
-
#{@native}[#{method}](#{state_or_prop.shallow_to_n}, function(){
|
|
44
|
-
#{block.call if block}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
data/lib/react/component/base.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
class Base
|
|
4
|
-
def self.inherited(child)
|
|
5
|
-
# note this is turned off during old style testing: See the spec_helper
|
|
6
|
-
unless child.to_s == "React::Component::HyperTestDummy"
|
|
7
|
-
React::Component.deprecation_warning child, "The class name React::Component::Base has been deprecated. Use Hyperloop::Component instead."
|
|
8
|
-
end
|
|
9
|
-
child.include(ComponentNoNotice)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
# class level methods (macros) for components
|
|
4
|
-
module ClassMethods
|
|
5
|
-
|
|
6
|
-
def deprecation_warning(message)
|
|
7
|
-
React::Component.deprecation_warning(self, message)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def reactrb_component?
|
|
11
|
-
true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def backtrace(*args)
|
|
15
|
-
@dont_catch_exceptions = (args[0] == :none)
|
|
16
|
-
@backtrace_off = @dont_catch_exceptions || (args[0] == :off)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def process_exception(e, component, reraise = @dont_catch_exceptions)
|
|
20
|
-
unless @dont_catch_exceptions
|
|
21
|
-
message = ["Exception raised while rendering #{component}: #{e.message}"]
|
|
22
|
-
if e.backtrace && e.backtrace.length > 1 && !@backtrace_off
|
|
23
|
-
append_backtrace(message, e.backtrace)
|
|
24
|
-
end
|
|
25
|
-
`console.error(#{message.join("\n")})`
|
|
26
|
-
end
|
|
27
|
-
raise e if reraise
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def append_backtrace(message_array, backtrace)
|
|
31
|
-
message_array << " #{backtrace[0]}"
|
|
32
|
-
backtrace[1..-1].each { |line| message_array << line }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def render(container = nil, params = {}, &block)
|
|
36
|
-
if container
|
|
37
|
-
container = container.type if container.is_a? React::Element
|
|
38
|
-
define_method :render do
|
|
39
|
-
React::RenderingContext.render(container, params) { instance_eval(&block) if block }
|
|
40
|
-
end
|
|
41
|
-
else
|
|
42
|
-
define_method(:render) { instance_eval(&block) }
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# method missing will assume the method is a class name, and will treat this a render of
|
|
47
|
-
# of the component, i.e. Foo::Bar.baz === Foo::Bar().baz
|
|
48
|
-
|
|
49
|
-
def method_missing(name, *args, &children)
|
|
50
|
-
Object.method_missing(name, *args, &children) unless args.empty?
|
|
51
|
-
React::RenderingContext.render(
|
|
52
|
-
self, class: React::Element.haml_class_name(name), &children
|
|
53
|
-
)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def validator
|
|
57
|
-
@validator ||= Validator.new(props_wrapper)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def prop_types
|
|
61
|
-
if self.validator
|
|
62
|
-
{
|
|
63
|
-
_componentValidator: %x{
|
|
64
|
-
function(props, propName, componentName) {
|
|
65
|
-
var errors = #{validator.validate(Hash.new(`props`))};
|
|
66
|
-
var error = new Error(#{"In component `#{name}`\n" + `errors`.join("\n")});
|
|
67
|
-
return #{`errors`.count > 0 ? `error` : `undefined`};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else
|
|
72
|
-
{}
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def default_props
|
|
77
|
-
validator.default_props
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def params(&block)
|
|
81
|
-
validator.build(&block)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def props_wrapper
|
|
85
|
-
@props_wrapper ||= Class.new(PropsWrapper)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def param(*args)
|
|
89
|
-
if args[0].is_a? Hash
|
|
90
|
-
options = args[0]
|
|
91
|
-
name = options.first[0]
|
|
92
|
-
default = options.first[1]
|
|
93
|
-
options.delete(name)
|
|
94
|
-
options.merge!({default: default})
|
|
95
|
-
else
|
|
96
|
-
name = args[0]
|
|
97
|
-
options = args[1] || {}
|
|
98
|
-
end
|
|
99
|
-
if options[:default]
|
|
100
|
-
validator.optional(name, options)
|
|
101
|
-
else
|
|
102
|
-
validator.requires(name, options)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def collect_other_params_as(name)
|
|
107
|
-
validator.allow_undefined_props = true
|
|
108
|
-
validator_in_lexical_scope = validator
|
|
109
|
-
props_wrapper.define_method(name) do
|
|
110
|
-
@_all_others ||= validator_in_lexical_scope.undefined_props(props)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
validator_in_lexial_scope = validator
|
|
114
|
-
props_wrapper.define_method(name) do
|
|
115
|
-
@_all_others ||= validator_in_lexial_scope.undefined_props(props)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def define_state(*states, &block)
|
|
120
|
-
deprecation_warning "'define_state' is deprecated. Use the 'state' macro to declare states."
|
|
121
|
-
default_initial_value = (block && block.arity == 0) ? yield : nil
|
|
122
|
-
states_hash = (states.last.is_a?(Hash)) ? states.pop : {}
|
|
123
|
-
states.each { |name| state(name => default_initial_value) } # was states_hash[name] = default_initial_value
|
|
124
|
-
states_hash.each { |name, value| state(name => value) }
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def export_state(*states, &block)
|
|
128
|
-
deprecation_warning "'export_state' is deprecated. Use the 'state' macro to declare states."
|
|
129
|
-
default_initial_value = (block && block.arity == 0) ? yield : nil
|
|
130
|
-
states_hash = (states.last.is_a?(Hash)) ? states.pop : {}
|
|
131
|
-
states.each { |name| states_hash[name] = default_initial_value }
|
|
132
|
-
states_hash.each do |name, value|
|
|
133
|
-
state(name => value, scope: :class, reader: true)
|
|
134
|
-
singleton_class.define_method("#{name}!") do |*args|
|
|
135
|
-
mutate.__send__(name, *args)
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def native_mixin(item)
|
|
141
|
-
native_mixins << item
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def native_mixins
|
|
145
|
-
@native_mixins ||= []
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def static_call_back(name, &block)
|
|
149
|
-
static_call_backs[name] = block
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def static_call_backs
|
|
153
|
-
@static_call_backs ||= {}
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def export_component(opts = {})
|
|
157
|
-
export_name = (opts[:as] || name).split('::')
|
|
158
|
-
first_name = export_name.first
|
|
159
|
-
Native(`Opal.global`)[first_name] = add_item_to_tree(
|
|
160
|
-
Native(`Opal.global`)[first_name],
|
|
161
|
-
[React::API.create_native_react_class(self)] + export_name[1..-1].reverse
|
|
162
|
-
).to_n
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def imports(component_name)
|
|
166
|
-
React::API.import_native_component(
|
|
167
|
-
self, React::API.eval_native_react_component(component_name)
|
|
168
|
-
)
|
|
169
|
-
define_method(:render) {} # define a dummy render method - will never be called...
|
|
170
|
-
rescue Exception => e # rubocop:disable Lint/RescueException : we need to catch everything!
|
|
171
|
-
raise "#{self} cannot import '#{component_name}': #{e.message}."
|
|
172
|
-
# rubocop:enable Lint/RescueException
|
|
173
|
-
ensure
|
|
174
|
-
self
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
def add_item_to_tree(current_tree, new_item)
|
|
178
|
-
if Native(current_tree).class != Native::Object || new_item.length == 1
|
|
179
|
-
new_item.inject { |a, e| { e => a } }
|
|
180
|
-
else
|
|
181
|
-
Native(current_tree)[new_item.last] = add_item_to_tree(
|
|
182
|
-
Native(current_tree)[new_item.last], new_item[0..-2]
|
|
183
|
-
)
|
|
184
|
-
current_tree
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|