isomorfeus-react 16.12.11 → 16.12.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus/config.rb +13 -0
- data/lib/isomorfeus/props/validator.rb +16 -16
- data/lib/isomorfeus/react_view_helper.rb +21 -11
- data/lib/isomorfeus/top_level.rb +1 -1
- data/lib/isomorfeus-react.rb +0 -1
- data/lib/isomorfeus_react/lucid_app/mixin.rb +0 -1
- data/lib/isomorfeus_react/lucid_app/native_lucid_component_constructor.rb +0 -4
- data/lib/isomorfeus_react/lucid_component/mixin.rb +0 -1
- data/lib/isomorfeus_react/lucid_component/native_lucid_component_constructor.rb +0 -4
- data/lib/isomorfeus_react/lucid_func/initializer.rb +0 -8
- data/lib/isomorfeus_react/lucid_func/mixin.rb +0 -1
- data/lib/isomorfeus_react/react/function_component/api.rb +11 -1
- data/lib/isomorfeus_react/react/function_component/initializer.rb +0 -8
- data/lib/isomorfeus_react/react/function_component/mixin.rb +0 -1
- data/lib/isomorfeus_react/react/memo_component/mixin.rb +0 -1
- data/lib/isomorfeus_react_material/lucid_material/app/mixin.rb +0 -1
- data/lib/isomorfeus_react_material/lucid_material/component/mixin.rb +0 -1
- data/lib/isomorfeus_react_material/lucid_material/func/mixin.rb +0 -1
- data/lib/lucid_prop_declaration/mixin.rb +1 -1
- data/lib/react/component/api.rb +2 -1
- data/lib/react/component/mixin.rb +0 -1
- data/lib/react/component/native_component_constructor.rb +0 -4
- data/lib/react/native_constant_wrapper.rb +1 -1
- data/lib/react/version.rb +1 -1
- data/lib/react.rb +48 -3
- metadata +9 -5
- data/lib/isomorfeus_react/react/function_component/event_handler.rb +0 -21
- data/lib/react/component/event_handler.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 331181f0913df3ce50e11f4e6d4aa062bd6d329a8d4442d0c0d00c7ff9041a1d
|
4
|
+
data.tar.gz: 9f0c73b00b5a5476b47a62bf6212df26ee69144445af822ee167a5e018495c32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5f8afde93bbd151bc29b8e28fc38951c75380de3bea39fc85b6df2ddaf5da8cab28bd5e387610298c8cb56bbc2f15ba7db1ec56f6b91cd336f25bdfd160a1d2
|
7
|
+
data.tar.gz: 0763e89fb0c282cb7294e02caa355d92ba39acc95c13e8fc7fb4ff39f30652425a0489b11d64a8f8137e611ccf3fb602e15c82b15e644c2d0c30929dcc75d12d
|
data/lib/isomorfeus/config.rb
CHANGED
@@ -147,4 +147,17 @@ module Isomorfeus
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
150
|
+
|
151
|
+
class << self
|
152
|
+
def raise_error(error_class: nil, message: nil, stack: nil)
|
153
|
+
error_class = RuntimeError unless error_class
|
154
|
+
execution_environment = if on_browser? then 'on Browser'
|
155
|
+
elsif on_ssr? then 'in Server Side Rendering'
|
156
|
+
elsif on_server? then 'on Server'
|
157
|
+
end
|
158
|
+
error = error_class.new("Isomorfeus in #{env} #{execution_environment}:\n#{message}")
|
159
|
+
error.set_backtrace(stack) if stack
|
160
|
+
raise error
|
161
|
+
end
|
162
|
+
end
|
150
163
|
end
|
@@ -34,7 +34,7 @@ module Isomorfeus
|
|
34
34
|
end
|
35
35
|
@v = !!@v if @o[:type] == :boolean
|
36
36
|
rescue
|
37
|
-
|
37
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} cast failed") unless @v.class == @o[:class]
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -54,13 +54,13 @@ module Isomorfeus
|
|
54
54
|
def type!
|
55
55
|
return if @o[:allow_nil] && @v.nil?
|
56
56
|
if @o.key?(:class)
|
57
|
-
|
57
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} class not #{@o[:class]}") unless @v.class == @o[:class]
|
58
58
|
elsif @o.key?(:is_a)
|
59
|
-
|
59
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a #{@o[:is_a]}") unless @v.is_a?(@o[:is_a])
|
60
60
|
elsif @o.key?(:type)
|
61
61
|
case @o[:type]
|
62
62
|
when :boolean
|
63
|
-
|
63
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a boolean") unless @v.class == TrueClass || @v.class == FalseClass
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -77,48 +77,48 @@ module Isomorfeus
|
|
77
77
|
|
78
78
|
# specific validations
|
79
79
|
def c_gt(v)
|
80
|
-
|
80
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} not greater than #{v}!") unless @v > v
|
81
81
|
end
|
82
82
|
|
83
83
|
def c_lt(v)
|
84
|
-
|
84
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} not less than #{v}!") unless @v < v
|
85
85
|
end
|
86
86
|
|
87
87
|
def c_keys(v)
|
88
|
-
|
88
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} keys dont fit!") unless @v.keys.sort == v.sort
|
89
89
|
end
|
90
90
|
|
91
91
|
def c_size(v)
|
92
|
-
|
92
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} length/size is not #{v}") unless @v.size == v
|
93
93
|
end
|
94
94
|
|
95
95
|
def c_matches(v)
|
96
|
-
|
96
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} does not match #{v}") unless v.match?(@v)
|
97
97
|
end
|
98
98
|
|
99
99
|
def c_max(v)
|
100
|
-
|
100
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is larger than #{v}") unless @v <= v
|
101
101
|
end
|
102
102
|
|
103
103
|
def c_min(v)
|
104
|
-
|
104
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is smaller than #{v}") unless @v >= v
|
105
105
|
end
|
106
106
|
|
107
107
|
def c_max_size(v)
|
108
|
-
|
108
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is larger than #{v}") unless @v.size <= v
|
109
109
|
end
|
110
110
|
|
111
111
|
def c_min_size(v)
|
112
|
-
|
112
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is smaller than #{v}") unless @v.size >= v
|
113
113
|
end
|
114
114
|
|
115
115
|
def c_direction(v)
|
116
|
-
|
117
|
-
|
116
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is positive") if v == :negative && @v >= 0
|
117
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} is negative") if v == :positive && @v < 0
|
118
118
|
end
|
119
119
|
|
120
120
|
def c_test
|
121
|
-
|
121
|
+
Isomorfeus.raise_error(message: "#{@c}: #{@p} test condition check failed") unless @o[:test].call(@v)
|
122
122
|
end
|
123
123
|
|
124
124
|
def c_sub_type(v)
|
@@ -35,12 +35,15 @@ module Isomorfeus
|
|
35
35
|
begin
|
36
36
|
asset = Net::HTTP.get(URI(asset_path))
|
37
37
|
rescue Exception => e
|
38
|
-
|
38
|
+
Isomorfeus.raise_error(message: "Server Side Rendering: Failed loading asset #{asset_path} from webpack dev server. Error: #{e.message}")
|
39
|
+
end
|
40
|
+
if asset.strip.start_with?('<')
|
41
|
+
Isomorfeus.raise_error(message: "Server Side Rendering: Failed loading asset #{asset_path} from webpack dev server, asset is not javascript. Did the webpack build succeed?")
|
39
42
|
end
|
40
43
|
begin
|
41
44
|
Isomorfeus.ssr_contexts[thread_id_asset] = ExecJS.permissive_compile(asset)
|
42
45
|
rescue Exception => e
|
43
|
-
|
46
|
+
Isomorfeus.raise_error(message: "Server Side Rendering: Failed creating context for #{asset_path}. Error: #{e.message}")
|
44
47
|
end
|
45
48
|
else
|
46
49
|
# initialize speednode context
|
@@ -58,6 +61,7 @@ module Isomorfeus
|
|
58
61
|
global.Opal.React.active_components = [];
|
59
62
|
global.Opal.React.active_redux_components = [];
|
60
63
|
global.FirstPassFinished = false;
|
64
|
+
global.Exception = false;
|
61
65
|
global.Opal.Isomorfeus['$env=']('#{Isomorfeus.env}');
|
62
66
|
if (typeof global.Opal.Isomorfeus.$negotiated_locale === 'function') {
|
63
67
|
global.Opal.Isomorfeus["$negotiated_locale="]('#{props[:locale]}');
|
@@ -74,14 +78,18 @@ module Isomorfeus
|
|
74
78
|
api_ws_path = Isomorfeus.respond_to?(:api_websocket_path) ? Isomorfeus.api_websocket_path : ''
|
75
79
|
transport_ws_url = ws_scheme + location_host + api_ws_path
|
76
80
|
javascript << <<~JAVASCRIPT
|
77
|
-
|
81
|
+
let api_ws_path = '#{api_ws_path}';
|
82
|
+
let exception;
|
78
83
|
if (typeof global.Opal.Isomorfeus.Transport !== 'undefined' && api_ws_path !== '') {
|
79
84
|
global.Opal.Isomorfeus.TopLevel["$transport_ws_url="]("#{transport_ws_url}");
|
80
85
|
global.Opal.send(global.Opal.Isomorfeus.Transport.$promise_connect(), 'then', [], ($$1 = function(){
|
81
86
|
try {
|
82
87
|
global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)});
|
83
88
|
global.FirstPassFinished = 'transport';
|
84
|
-
} catch (e) {
|
89
|
+
} catch (e) {
|
90
|
+
global.Exception = e;
|
91
|
+
global.FirstPassFinished = 'transport';
|
92
|
+
}
|
85
93
|
}, $$1.$$s = this, $$1.$$arity = 0, $$1))
|
86
94
|
} else { return global.FirstPassFinished = true; };
|
87
95
|
JAVASCRIPT
|
@@ -91,7 +99,8 @@ module Isomorfeus
|
|
91
99
|
|
92
100
|
# wait for first pass to finish
|
93
101
|
unless first_pass_skipped
|
94
|
-
first_pass_finished = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.FirstPassFinished')
|
102
|
+
first_pass_finished, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec('return [global.FirstPassFinished, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false ]')
|
103
|
+
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
95
104
|
unless first_pass_finished
|
96
105
|
start_time = Time.now
|
97
106
|
while !first_pass_finished
|
@@ -121,6 +130,7 @@ module Isomorfeus
|
|
121
130
|
global.Opal.React.render_buffer = [];
|
122
131
|
global.Opal.React.active_components = [];
|
123
132
|
global.Opal.React.active_redux_components = [];
|
133
|
+
global.Exception = false;
|
124
134
|
let rendered_tree;
|
125
135
|
let ssr_styles;
|
126
136
|
let component;
|
@@ -135,7 +145,7 @@ module Isomorfeus
|
|
135
145
|
rendered_tree = global.Opal.global.ReactDOMServer.renderToString(sheets.collect(app));
|
136
146
|
ssr_styles = sheets.toString();
|
137
147
|
} catch (e) {
|
138
|
-
|
148
|
+
global.Exception = e;
|
139
149
|
}
|
140
150
|
} else if (typeof global.Opal.global.ReactJSS !== 'undefined' && typeof global.Opal.global.ReactJSS.SheetsRegistry !== 'undefined') {
|
141
151
|
component = '#{component_name}'.split(".").reduce(function(o, x) {
|
@@ -150,26 +160,26 @@ module Isomorfeus
|
|
150
160
|
rendered_tree = global.Opal.global.ReactDOMServer.renderToString(element);
|
151
161
|
ssr_styles = sheets.toString();
|
152
162
|
} catch (e) {
|
153
|
-
|
163
|
+
global.Exception = e;
|
154
164
|
}
|
155
165
|
} else {
|
156
166
|
try {
|
157
167
|
rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)});
|
158
168
|
} catch (e) {
|
159
|
-
|
169
|
+
global.Exception = e;
|
160
170
|
}
|
161
171
|
}
|
162
172
|
let application_state = global.Opal.Isomorfeus.store.native.getState();
|
163
173
|
if (typeof global.Opal.Isomorfeus.Transport !== 'undefined') { global.Opal.Isomorfeus.Transport.$disconnect(); }
|
164
|
-
return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status']()];
|
174
|
+
return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](), global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
|
165
175
|
JAVASCRIPT
|
166
176
|
|
167
177
|
# execute second render pass
|
168
|
-
rendered_tree, application_state, @ssr_styles, @ssr_response_status = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
178
|
+
rendered_tree, application_state, @ssr_styles, @ssr_response_status, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
179
|
+
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
169
180
|
|
170
181
|
# build result
|
171
182
|
render_result << " data-iso-hydrated='true'" if rendered_tree
|
172
|
-
# render_result << " data-iso-nloc='#{props[:locale]}' data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
|
173
183
|
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
174
184
|
render_result << (rendered_tree ? rendered_tree : "SSR didn't work")
|
175
185
|
else
|
data/lib/isomorfeus/top_level.rb
CHANGED
@@ -5,7 +5,7 @@ module Isomorfeus
|
|
5
5
|
Isomorfeus.init
|
6
6
|
Isomorfeus::TopLevel.on_ready do
|
7
7
|
root_element = `document.querySelector('div[data-iso-root]')`
|
8
|
-
|
8
|
+
Isomorfeus.raise_error(message: "Isomorfeus root element not found!") unless root_element
|
9
9
|
component_name = root_element.JS.getAttribute('data-iso-root')
|
10
10
|
Isomorfeus.env = root_element.JS.getAttribute('data-iso-env')
|
11
11
|
component = nil
|
data/lib/isomorfeus-react.rb
CHANGED
@@ -71,7 +71,6 @@ if RUBY_ENGINE == 'opal'
|
|
71
71
|
require 'react/component/location'
|
72
72
|
require 'react/component/history'
|
73
73
|
require 'react/component/resolution'
|
74
|
-
require 'react/component/event_handler'
|
75
74
|
require 'react/component/styles'
|
76
75
|
require 'react/component/mixin'
|
77
76
|
require 'react/component/base'
|
@@ -5,7 +5,6 @@ module LucidApp
|
|
5
5
|
base.extend(::LucidApp::NativeLucidComponentConstructor)
|
6
6
|
base.extend(::LucidApp::NativeComponentConstructor)
|
7
7
|
base.extend(::LucidPropDeclaration::Mixin)
|
8
|
-
base.extend(::React::Component::EventHandler)
|
9
8
|
base.extend(::LucidComponent::EnvironmentSupport)
|
10
9
|
base.include(::LucidComponent::EnvironmentSupport)
|
11
10
|
base.include(::React::Component::Elements)
|
@@ -32,10 +32,6 @@ module LucidApp
|
|
32
32
|
this.state.component_state = {};
|
33
33
|
this.state.component_state[this.__object_id] = {};
|
34
34
|
};
|
35
|
-
var event_handlers = #{base.event_handlers};
|
36
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
37
|
-
this[event_handlers[i]] = this[event_handlers[i]].bind(this);
|
38
|
-
}
|
39
35
|
var defined_refs = #{base.defined_refs};
|
40
36
|
for (var ref in defined_refs) {
|
41
37
|
if (defined_refs[ref] != null) {
|
@@ -5,7 +5,6 @@ module LucidComponent
|
|
5
5
|
base.extend(::LucidComponent::NativeLucidComponentConstructor)
|
6
6
|
base.extend(::LucidComponent::NativeComponentConstructor)
|
7
7
|
base.extend(::LucidPropDeclaration::Mixin)
|
8
|
-
base.extend(::React::Component::EventHandler)
|
9
8
|
base.extend(::LucidComponent::EnvironmentSupport)
|
10
9
|
base.include(::LucidComponent::EnvironmentSupport)
|
11
10
|
base.include(::React::Component::Elements)
|
@@ -22,10 +22,6 @@ module LucidComponent
|
|
22
22
|
this.state.component_state = {};
|
23
23
|
this.state.component_state[this.__object_id] = {};
|
24
24
|
};
|
25
|
-
var event_handlers = #{base.event_handlers};
|
26
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
27
|
-
this[event_handlers[i]] = this[event_handlers[i]].bind(this);
|
28
|
-
}
|
29
25
|
var defined_refs = #{base.defined_refs};
|
30
26
|
for (var ref in defined_refs) {
|
31
27
|
if (defined_refs[ref] != null) {
|
@@ -6,14 +6,6 @@ module LucidFunc
|
|
6
6
|
@app_store = LucidComponent::AppStoreProxy.new(self)
|
7
7
|
@class_store = LucidComponent::ClassStoreProxy.new(self)
|
8
8
|
@store = LucidComponent::InstanceStoreProxy.new(self)
|
9
|
-
event_handlers = self.class.event_handlers
|
10
|
-
event_handler_source = self.class
|
11
|
-
%x{
|
12
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
13
|
-
self[event_handlers[i]] = event_handler_source[event_handlers[i]];
|
14
|
-
self[event_handlers[i]] = self[event_handlers[i]].bind(self);
|
15
|
-
}
|
16
|
-
}
|
17
9
|
end
|
18
10
|
end
|
19
11
|
end
|
@@ -5,7 +5,6 @@ module LucidFunc
|
|
5
5
|
base.include(::React::Component::Features)
|
6
6
|
base.include(::LucidFunc::Initializer)
|
7
7
|
base.include(::React::FunctionComponent::Api)
|
8
|
-
base.extend(::React::FunctionComponent::EventHandler)
|
9
8
|
base.extend(::LucidComponent::EnvironmentSupport)
|
10
9
|
base.include(::LucidComponent::EnvironmentSupport)
|
11
10
|
base.extend(::LucidFunc::NativeComponentConstructor)
|
@@ -66,7 +66,7 @@ module React
|
|
66
66
|
block.$call();
|
67
67
|
// console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())
|
68
68
|
let new_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop();
|
69
|
-
if (last_buffer_element === new_element) { #{
|
69
|
+
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any React element!")} }
|
70
70
|
return new_element;
|
71
71
|
}
|
72
72
|
else
|
@@ -86,6 +86,16 @@ module React
|
|
86
86
|
end
|
87
87
|
alias rre render_react_element
|
88
88
|
|
89
|
+
def method_ref(method_symbol)
|
90
|
+
%x{
|
91
|
+
if (#{self}.method_refs && #{self}.method_refs[#{method_symbol}]) { return #{self}.method_refs[#{method_symbol}]; }
|
92
|
+
if (!#{self}.method_refs) { #{self}.method_refs = {}; }
|
93
|
+
#{self}.method_refs[#{method_symbol}] = #{method(method_symbol)};
|
94
|
+
return #{self}.method_refs[#{method_symbol}];
|
95
|
+
}
|
96
|
+
end
|
97
|
+
alias m_ref method_ref
|
98
|
+
|
89
99
|
def to_n
|
90
100
|
self
|
91
101
|
end
|
@@ -4,14 +4,6 @@ module React
|
|
4
4
|
def initialize
|
5
5
|
self.JS[:native_props] = `{ props: null }`
|
6
6
|
@native_props = ::React::Component::Props.new(self)
|
7
|
-
event_handlers = self.class.event_handlers
|
8
|
-
event_handler_source = self.class
|
9
|
-
%x{
|
10
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
11
|
-
self[event_handlers[i]] = event_handler_source[event_handlers[i]];
|
12
|
-
self[event_handlers[i]] = self[event_handlers[i]].bind(self);
|
13
|
-
}
|
14
|
-
}
|
15
7
|
end
|
16
8
|
end
|
17
9
|
end
|
@@ -6,7 +6,6 @@ module React
|
|
6
6
|
base.include(::React::Component::Features)
|
7
7
|
base.include(::React::FunctionComponent::Initializer)
|
8
8
|
base.include(::React::FunctionComponent::Api)
|
9
|
-
base.extend(::React::FunctionComponent::EventHandler)
|
10
9
|
base.extend(::React::FunctionComponent::NativeComponentConstructor)
|
11
10
|
end
|
12
11
|
end
|
@@ -6,7 +6,6 @@ module React
|
|
6
6
|
base.include(::React::Component::Features)
|
7
7
|
base.include(::React::FunctionComponent::Initializer)
|
8
8
|
base.include(::React::FunctionComponent::Api)
|
9
|
-
base.extend(::React::FunctionComponent::EventHandler)
|
10
9
|
base.extend(::React::MemoComponent::NativeComponentConstructor)
|
11
10
|
end
|
12
11
|
end
|
@@ -6,7 +6,6 @@ module LucidMaterial
|
|
6
6
|
base.extend(::LucidApp::NativeLucidComponentConstructor)
|
7
7
|
base.extend(::LucidMaterial::App::NativeComponentConstructor)
|
8
8
|
base.extend(::LucidPropDeclaration::Mixin)
|
9
|
-
base.extend(::React::Component::EventHandler)
|
10
9
|
base.extend(::LucidComponent::EnvironmentSupport)
|
11
10
|
base.include(::LucidComponent::EnvironmentSupport)
|
12
11
|
base.include(::React::Component::Elements)
|
@@ -6,7 +6,6 @@ module LucidMaterial
|
|
6
6
|
base.extend(::LucidComponent::NativeLucidComponentConstructor)
|
7
7
|
base.extend(::LucidMaterial::Component::NativeComponentConstructor)
|
8
8
|
base.extend(::LucidPropDeclaration::Mixin)
|
9
|
-
base.extend(::React::Component::EventHandler)
|
10
9
|
base.extend(::LucidComponent::EnvironmentSupport)
|
11
10
|
base.include(::LucidComponent::EnvironmentSupport)
|
12
11
|
base.include(::React::Component::Elements)
|
@@ -6,7 +6,6 @@ module LucidMaterial
|
|
6
6
|
base.include(::React::Component::Features)
|
7
7
|
base.include(::LucidFunc::Initializer)
|
8
8
|
base.include(::React::FunctionComponent::Api)
|
9
|
-
base.extend(::React::FunctionComponent::EventHandler)
|
10
9
|
base.extend(::LucidComponent::EnvironmentSupport)
|
11
10
|
base.include(::LucidComponent::EnvironmentSupport)
|
12
11
|
base.extend(::LucidMaterial::Func::NativeComponentConstructor)
|
@@ -78,7 +78,7 @@ module LucidPropDeclaration
|
|
78
78
|
props = {} unless props
|
79
79
|
declared_props.each_key do |prop|
|
80
80
|
if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
|
81
|
-
|
81
|
+
Isomorfeus.raise_error(message: "Required prop #{prop} not given!")
|
82
82
|
end
|
83
83
|
end
|
84
84
|
result = true
|
data/lib/react/component/api.rb
CHANGED
@@ -86,7 +86,7 @@ module React
|
|
86
86
|
block.$call();
|
87
87
|
// console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())
|
88
88
|
let new_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop();
|
89
|
-
if (last_buffer_element === new_element) { #{
|
89
|
+
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any React element!")} }
|
90
90
|
return new_element;
|
91
91
|
}
|
92
92
|
else
|
@@ -106,6 +106,7 @@ module React
|
|
106
106
|
return #@native.method_refs[#{method_symbol}];
|
107
107
|
}
|
108
108
|
end
|
109
|
+
alias m_ref method_ref
|
109
110
|
|
110
111
|
def render_react_element(el)
|
111
112
|
# push el to buffer
|
@@ -5,7 +5,6 @@ module React
|
|
5
5
|
base.include(::Native::Wrapper)
|
6
6
|
base.extend(::React::Component::NativeComponentConstructor)
|
7
7
|
base.extend(::LucidPropDeclaration::Mixin)
|
8
|
-
base.extend(::React::Component::EventHandler)
|
9
8
|
base.include(::React::Component::Elements)
|
10
9
|
base.include(::React::Component::Api)
|
11
10
|
base.include(::React::Component::Callbacks)
|
@@ -17,10 +17,6 @@ module React
|
|
17
17
|
this.state = {};
|
18
18
|
};
|
19
19
|
this.__ruby_instance = base.$new(this);
|
20
|
-
var event_handlers = #{base.event_handlers};
|
21
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
22
|
-
this[event_handlers[i]] = this[event_handlers[i]].bind(this);
|
23
|
-
}
|
24
20
|
var defined_refs = #{base.defined_refs};
|
25
21
|
for (var ref in defined_refs) {
|
26
22
|
if (defined_refs[ref] != null) {
|
@@ -22,7 +22,7 @@ module React
|
|
22
22
|
if (component) {
|
23
23
|
return Opal.React.internal_prepare_args_and_render(component, args, block);
|
24
24
|
} else {
|
25
|
-
#{
|
25
|
+
#{Isomorfeus.raise_error(error_class: NameError, message: "No such native Component #@const_name.#{name}")};
|
26
26
|
}
|
27
27
|
}
|
28
28
|
end
|
data/lib/react/version.rb
CHANGED
data/lib/react.rb
CHANGED
@@ -37,17 +37,62 @@ module React
|
|
37
37
|
key = keys[i];
|
38
38
|
if (key[0] === 'o' && key[1] === 'n' && key[2] === '_') {
|
39
39
|
let handler = ruby_style_props['$[]'](key);
|
40
|
-
|
40
|
+
let type = typeof handler;
|
41
|
+
if (type === "function") {
|
41
42
|
let active_c = self.active_component();
|
42
43
|
result[Opal.React.lower_camelize(key)] = function(event, info) {
|
43
44
|
let ruby_event;
|
44
45
|
if (typeof event === "object") { #{ruby_event = ::React::SyntheticEvent.new(`event`)}; }
|
45
|
-
else {
|
46
|
+
else { ruby_event = event; }
|
46
47
|
#{`active_c.__ruby_instance`.instance_exec(ruby_event, `info`, &`handler`)};
|
47
48
|
}
|
49
|
+
} else if (type === "object" && typeof handler.$call === "function" ) {
|
50
|
+
if (!handler.react_event_handler_function) {
|
51
|
+
handler.react_event_handler_function = function(event, info) {
|
52
|
+
let ruby_event;
|
53
|
+
if (typeof event === "object") { #{ruby_event = ::React::SyntheticEvent.new(`event`)}; }
|
54
|
+
else { ruby_event = event; }
|
55
|
+
handler.$call(ruby_event, `info`)
|
56
|
+
};
|
57
|
+
}
|
58
|
+
result[Opal.React.lower_camelize(key)] = handler.react_event_handler_function;
|
59
|
+
} else if (type === "string" ) {
|
60
|
+
let active_component = Opal.React.active_component();
|
61
|
+
let method_ref;
|
62
|
+
let method_name = '$' + handler;
|
63
|
+
if (typeof active_component[method_name] === "function") {
|
64
|
+
// got a ruby instance
|
65
|
+
if (active_component.native && active_component.native.method_refs && active_component.native.method_refs[handler]) { method_ref = active_component.native.method_refs[handler]; } // ruby instance with native
|
66
|
+
else if (active_component.method_refs && active_component.method_refs[handler]) { method_ref = active_component.method_refs[handler]; } // ruby function component
|
67
|
+
else { method_ref = active_component.$method_ref(handler); } // create the ref
|
68
|
+
} else if (typeof active_component.__ruby_instance[method_name] === "function") {
|
69
|
+
// got a native instance
|
70
|
+
if (active_component.method_refs && active_component.method_refs[handler]) { method_ref = active_component.method_refs[handler]; }
|
71
|
+
else { method_ref = active_component.__ruby_instance.$method_ref(handler); } // create ref for native
|
72
|
+
}
|
73
|
+
if (method_ref) {
|
74
|
+
if (!method_ref.react_event_handler_function) {
|
75
|
+
method_ref.react_event_handler_function = function(event, info) {
|
76
|
+
let ruby_event;
|
77
|
+
if (typeof event === "object") { #{ruby_event = ::React::SyntheticEvent.new(`event`)}; }
|
78
|
+
else { ruby_event = event; }
|
79
|
+
method_ref.$call(ruby_event, `info`)
|
80
|
+
};
|
81
|
+
}
|
82
|
+
result[Opal.React.lower_camelize(key)] = method_ref.react_event_handler_function;
|
83
|
+
} else {
|
84
|
+
let component_name;
|
85
|
+
if (active_component.__ruby_instance) { component_name = active_component.__ruby_instance.$to_s(); }
|
86
|
+
else { component_name = active_component.$to_s(); }
|
87
|
+
#{Isomorfeus.raise_error(message: "Is #{`handler`} a valid method of #{`component_name`}? If so then please use: #{`key`}: method_ref(:#{`handler`}) within component: #{`component_name`}")}
|
88
|
+
}
|
48
89
|
} else {
|
49
90
|
let active_component = Opal.React.active_component();
|
50
|
-
|
91
|
+
let component_name;
|
92
|
+
if (active_component.__ruby_instance) { component_name = active_component.__ruby_instance.$to_s(); }
|
93
|
+
else { component_name = active_component.$to_s(); }
|
94
|
+
#{Isomorfeus.raise_error(message: "Received invalid value for #{`key`} with #{`handler`} within component: #{`component_name`}")}
|
95
|
+
console.error( + key + " event handler:", handler, " within component:", self.active_component());
|
51
96
|
}
|
52
97
|
} else if (key[0] === 'a' && key.startsWith("aria_")) {
|
53
98
|
result[key.replace("_", "-")] = ruby_style_props['$[]'](key);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-react
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 16.12.
|
4
|
+
version: 16.12.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -228,7 +228,6 @@ files:
|
|
228
228
|
- lib/isomorfeus_react/lucid_func/native_component_constructor.rb
|
229
229
|
- lib/isomorfeus_react/react/function_component/api.rb
|
230
230
|
- lib/isomorfeus_react/react/function_component/base.rb
|
231
|
-
- lib/isomorfeus_react/react/function_component/event_handler.rb
|
232
231
|
- lib/isomorfeus_react/react/function_component/initializer.rb
|
233
232
|
- lib/isomorfeus_react/react/function_component/mixin.rb
|
234
233
|
- lib/isomorfeus_react/react/function_component/native_component_constructor.rb
|
@@ -253,7 +252,6 @@ files:
|
|
253
252
|
- lib/react/component/base.rb
|
254
253
|
- lib/react/component/callbacks.rb
|
255
254
|
- lib/react/component/elements.rb
|
256
|
-
- lib/react/component/event_handler.rb
|
257
255
|
- lib/react/component/features.rb
|
258
256
|
- lib/react/component/history.rb
|
259
257
|
- lib/react/component/initializer.rb
|
@@ -277,7 +275,13 @@ licenses:
|
|
277
275
|
- MIT
|
278
276
|
metadata:
|
279
277
|
github_repo: ssh://github.com/isomorfeus/gems
|
280
|
-
post_install_message:
|
278
|
+
post_install_message: |2+
|
279
|
+
|
280
|
+
isomorfeus-react 16.12.12:
|
281
|
+
Breaking change:
|
282
|
+
The event_handler DSL is gone. Instead use normal methods and method_ref, see:
|
283
|
+
https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/events.md
|
284
|
+
|
281
285
|
rdoc_options: []
|
282
286
|
require_paths:
|
283
287
|
- lib
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module FunctionComponent
|
3
|
-
module EventHandler
|
4
|
-
def event_handlers
|
5
|
-
@event_handlers ||= []
|
6
|
-
end
|
7
|
-
|
8
|
-
def event_handler(name, &block)
|
9
|
-
event_handlers << name
|
10
|
-
%x{
|
11
|
-
var fun = function(event, info) {
|
12
|
-
if (typeof event === "object") { #{ruby_event = ::React::SyntheticEvent.new(`event`)}; }
|
13
|
-
else { #{ruby_event = `event`}; }
|
14
|
-
#{`this`.instance_exec(ruby_event, `info`, &block)};
|
15
|
-
}
|
16
|
-
self[name] = fun;
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
module EventHandler
|
4
|
-
def event_handlers
|
5
|
-
@event_handlers ||= []
|
6
|
-
end
|
7
|
-
|
8
|
-
def event_handler(name, &block)
|
9
|
-
event_handlers << name
|
10
|
-
%x{
|
11
|
-
var fun = function(event, info) {
|
12
|
-
let ruby_event;
|
13
|
-
if (typeof event === "object") { #{ruby_event = ::React::SyntheticEvent.new(`event`)}; }
|
14
|
-
else { #{ruby_event = `event`}; }
|
15
|
-
#{`this.__ruby_instance`.instance_exec(ruby_event, `info`, &block)};
|
16
|
-
}
|
17
|
-
if (self.lucid_react_component) { self.lucid_react_component.prototype[name] = fun; }
|
18
|
-
else { self.react_component.prototype[name] = fun; }
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|