hyper-react 0.12.7 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/spec/react/dsl_spec.rb
DELETED
@@ -1,303 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
describe 'the React DSL', type: :component do
|
5
|
-
|
6
|
-
context "render macro" do
|
7
|
-
|
8
|
-
it "can define the render method with the render macro with a html tag container" do
|
9
|
-
stub_const 'Foo', Class.new
|
10
|
-
Foo.class_eval do
|
11
|
-
include React::Component
|
12
|
-
render(:div, class: :foo) do
|
13
|
-
"hello"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
expect(Foo).to render_static_html('<div class="foo">hello</div>')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "can define the render method with the render macro without a container" do
|
21
|
-
stub_const 'Foo', Class.new
|
22
|
-
Foo.class_eval do
|
23
|
-
include React::Component
|
24
|
-
render do
|
25
|
-
"hello"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
expect(Foo).to render_static_html('<span>hello</span>')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "can define the render method with the render macro with a application defined container" do
|
33
|
-
stub_const 'Bar', Class.new(React::Component::Base)
|
34
|
-
Bar.class_eval do
|
35
|
-
param :p1
|
36
|
-
render { "hello #{params.p1}" }
|
37
|
-
end
|
38
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
39
|
-
Foo.class_eval do
|
40
|
-
render Bar, p1: "fred"
|
41
|
-
end
|
42
|
-
|
43
|
-
expect(Foo).to render_static_html('<span>hello fred</span>')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it "will turn the last string in a block into a element" do
|
48
|
-
stub_const 'Foo', Class.new
|
49
|
-
Foo.class_eval do
|
50
|
-
include React::Component
|
51
|
-
def render
|
52
|
-
div { "hello" }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
expect(Foo).to render_static_html('<div>hello</div>')
|
57
|
-
end
|
58
|
-
|
59
|
-
it "will pass converted props through event handlers" do
|
60
|
-
stub_const 'Foo', Class.new
|
61
|
-
Foo.class_eval do
|
62
|
-
include React::Component
|
63
|
-
def render
|
64
|
-
INPUT(data: {foo: 12}).on(:change) {}
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo))).to match(/<input data-foo="12"(\/)?>/)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "will turn the last string in a block into a element" do
|
72
|
-
stub_const 'Foo', Class.new
|
73
|
-
Foo.class_eval do
|
74
|
-
include React::Component
|
75
|
-
def render
|
76
|
-
DIV { "hello" }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
expect(Foo).to render_static_html('<div>hello</div>')
|
81
|
-
end
|
82
|
-
|
83
|
-
it "has a .span short hand String method" do
|
84
|
-
stub_const 'Foo', Class.new
|
85
|
-
Foo.class_eval do
|
86
|
-
include React::Component
|
87
|
-
def render
|
88
|
-
div { "hello".span; "goodby".span }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
expect(Foo).to render_static_html('<div><span>hello</span><span>goodby</span></div>')
|
93
|
-
end
|
94
|
-
|
95
|
-
it "has a .br short hand String method" do
|
96
|
-
stub_const 'Foo', Class.new
|
97
|
-
Foo.class_eval do
|
98
|
-
include React::Component
|
99
|
-
def render
|
100
|
-
div { "hello".br }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo)).gsub("<br/>", "<br>")).to eq('<div><span>hello<br></span></div>')
|
105
|
-
end
|
106
|
-
|
107
|
-
it "has a .td short hand String method" do
|
108
|
-
stub_const 'Foo', Class.new
|
109
|
-
Foo.class_eval do
|
110
|
-
include React::Component
|
111
|
-
def render
|
112
|
-
table {
|
113
|
-
tbody {
|
114
|
-
tr { "hello".td }
|
115
|
-
}
|
116
|
-
}
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
expect(Foo).to render_static_html('<table><tbody><tr><td>hello</td></tr></tbody></table>')
|
121
|
-
end
|
122
|
-
|
123
|
-
it "has a .para short hand String method" do
|
124
|
-
stub_const 'Foo', Class.new
|
125
|
-
Foo.class_eval do
|
126
|
-
include React::Component
|
127
|
-
def render
|
128
|
-
div { "hello".para }
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
expect(Foo).to render_static_html('<div><p>hello</p></div>')
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'can do a method call on a class name that is not a direct sibling' do
|
136
|
-
stub_const 'Mod', Module.new
|
137
|
-
stub_const 'Mod::NestedMod', Module.new
|
138
|
-
stub_const 'Mod::Comp', Class.new(React::Component::Base)
|
139
|
-
Mod::Comp.class_eval do
|
140
|
-
render { 'Mod::Comp' }
|
141
|
-
end
|
142
|
-
stub_const 'Mod::NestedMod::NestedComp', Class.new(React::Component::Base)
|
143
|
-
Mod::NestedMod::NestedComp.class_eval do
|
144
|
-
render do
|
145
|
-
Comp()
|
146
|
-
end
|
147
|
-
end
|
148
|
-
expect(Mod::NestedMod::NestedComp)
|
149
|
-
.to render_static_html('<span>Mod::Comp</span>')
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'raises a meaningful error if a Constant Name is not actually a component' do
|
153
|
-
stub_const 'Mod', Module.new
|
154
|
-
stub_const 'Mod::NestedMod', Module.new
|
155
|
-
stub_const 'Mod::Comp', Class.new
|
156
|
-
stub_const 'Mod::NestedMod::NestedComp', Class.new(React::Component::Base)
|
157
|
-
Mod::NestedMod::NestedComp.class_eval do
|
158
|
-
backtrace :none
|
159
|
-
render do
|
160
|
-
Comp()
|
161
|
-
end
|
162
|
-
end
|
163
|
-
expect { React::Server.render_to_static_markup(React.create_element(Mod::NestedMod::NestedComp)) }
|
164
|
-
.to raise_error('Comp does not appear to be a react component.')
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'raises a method missing error' do
|
168
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
169
|
-
Foo.class_eval do
|
170
|
-
backtrace :none
|
171
|
-
render do
|
172
|
-
_undefined_method
|
173
|
-
end
|
174
|
-
end
|
175
|
-
expect { React::Server.render_to_static_markup(React.create_element(Foo)) }
|
176
|
-
.to raise_error(NoMethodError)
|
177
|
-
end
|
178
|
-
|
179
|
-
it "will treat the component class name as a first class component name" do
|
180
|
-
stub_const 'Mod::Bar', Class.new
|
181
|
-
Mod::Bar.class_eval do
|
182
|
-
include React::Component
|
183
|
-
def render
|
184
|
-
"a man walks into a bar"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
188
|
-
Foo.class_eval do
|
189
|
-
def render
|
190
|
-
Mod::Bar()
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
expect(Foo).to render_static_html('<span>a man walks into a bar</span>')
|
195
|
-
end
|
196
|
-
|
197
|
-
it "can add class names by the haml .class notation" do
|
198
|
-
stub_const 'Mod::Bar', Class.new
|
199
|
-
Mod::Bar.class_eval do
|
200
|
-
include React::Component
|
201
|
-
collect_other_params_as :attributes
|
202
|
-
def render
|
203
|
-
"a man walks into a bar".span(params.attributes)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
207
|
-
Foo.class_eval do
|
208
|
-
def render
|
209
|
-
Mod::Bar().the_class.other_class
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
expect(Foo).to render_static_html('<span class="other-class the-class">a man walks into a bar</span>')
|
214
|
-
end
|
215
|
-
|
216
|
-
it "can use the 'class' keyword for classes" do
|
217
|
-
stub_const 'Foo', Class.new
|
218
|
-
Foo.class_eval do
|
219
|
-
include React::Component
|
220
|
-
def render
|
221
|
-
span(class: "the-class") { "hello" }
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
expect(Foo).to render_static_html('<span class="the-class">hello</span>')
|
226
|
-
end
|
227
|
-
|
228
|
-
it "can generate a unrendered node using the .as_node method" do # div { "hello" }.as_node
|
229
|
-
stub_const 'Foo', Class.new #(React::Component::Base)
|
230
|
-
Foo.class_eval do
|
231
|
-
include React::Component
|
232
|
-
def render
|
233
|
-
span(data: {size: 12}) { "hello".span.as_node.class.name }.as_node.render
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
expect(Foo)
|
238
|
-
.to render_static_html('<span data-size="12">React::Element</span>')
|
239
|
-
end
|
240
|
-
|
241
|
-
it "can use the dangerously_set_inner_HTML param" do
|
242
|
-
stub_const 'Foo', Class.new
|
243
|
-
Foo.class_eval do
|
244
|
-
include React::Component
|
245
|
-
def render
|
246
|
-
div(dangerously_set_inner_HTML: { __html: "Hello Goodby" })
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
expect(Foo).to render_static_html('<div>Hello Goodby</div>')
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'should convert a hash param to hyphenated html attributes if in React::HASH_ATTRIBUTES' do
|
254
|
-
stub_const 'Foo', Class.new
|
255
|
-
Foo.class_eval do
|
256
|
-
include React::Component
|
257
|
-
def render
|
258
|
-
div(data: { foo: :bar }, aria: { label: "title" })
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
expect(Foo)
|
263
|
-
.to render_static_html('<div data-foo="bar" aria-label="title"></div>')
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'should not convert a hash param to hyphenated html attributes if not in React::HASH_ATTRIBUTES' do
|
267
|
-
stub_const 'Foo', Class.new
|
268
|
-
Foo.class_eval do
|
269
|
-
include React::Component
|
270
|
-
def render
|
271
|
-
div(title: { bar: :foo })
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
expect(Foo)
|
276
|
-
.to render_static_html(
|
277
|
-
'<div title="{"bar"=>"foo"}"></div>'
|
278
|
-
)
|
279
|
-
end
|
280
|
-
|
281
|
-
it "will remove all elements passed as params from the rendering buffer" do
|
282
|
-
stub_const 'X2', Class.new
|
283
|
-
X2.class_eval do
|
284
|
-
include React::Component
|
285
|
-
def render
|
286
|
-
div do
|
287
|
-
params[:ele].render
|
288
|
-
params[:ele].render
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
292
|
-
stub_const 'Test', Class.new
|
293
|
-
Test.class_eval do
|
294
|
-
include React::Component
|
295
|
-
def render
|
296
|
-
X2(ele: b { "hello" })
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
expect(Test).to render_static_html('<div><b>hello</b><b>hello</b></div>')
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
data/spec/react/element_spec.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
# require 'reactrb/new-event-name-convention' # this require will get rid of any error messages but
|
5
|
-
# the on method will no longer attach to the param prefixed with _on
|
6
|
-
describe React::Element, type: :component do
|
7
|
-
it 'bridges `type` of native React.Element attributes' do
|
8
|
-
element = React.create_element('div')
|
9
|
-
expect(element.element_type).to eq("div")
|
10
|
-
end
|
11
|
-
|
12
|
-
async 'is renderable' do
|
13
|
-
element = React.create_element('span')
|
14
|
-
div = `document.createElement("div")`
|
15
|
-
React.render(element, div) do
|
16
|
-
run_async {
|
17
|
-
expect(`div.children[0].tagName`).to eq("SPAN")
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "Event Subscription" do
|
23
|
-
it "keeps the original params" do
|
24
|
-
stub_const 'Foo', Class.new
|
25
|
-
Foo.class_eval do
|
26
|
-
include React::Component
|
27
|
-
def render
|
28
|
-
INPUT(value: nil, type: 'text').on(:change) {}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo))).to match(/<input (type="text" value=""|value="" type="text")(\/)?>/)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe 'Component Event Subscription' do
|
37
|
-
|
38
|
-
it 'will subscribe to a component event param' do
|
39
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
40
|
-
Foo.class_eval do
|
41
|
-
param :on_event, type: Proc, default: nil, allow_nil: true
|
42
|
-
def render
|
43
|
-
params.on_event
|
44
|
-
end
|
45
|
-
end
|
46
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo).on(:event) {'works!'})).to eq('<span>works!</span>')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'will subscribe to multiple component event params' do
|
50
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
51
|
-
Foo.class_eval do
|
52
|
-
param :on_event1, type: Proc, default: nil, allow_nil: true
|
53
|
-
param :on_event2, type: Proc, default: nil, allow_nil: true
|
54
|
-
def render
|
55
|
-
params.on_event1+params.on_event2
|
56
|
-
end
|
57
|
-
end
|
58
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo).on(:event1, :event2) {'works!'})).to eq('<span>works!works!</span>')
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'will subscribe to a native components event param' do
|
62
|
-
%x{
|
63
|
-
window.NativeComponent = React.createClass({
|
64
|
-
displayName: "HelloMessage",
|
65
|
-
render: function render() {
|
66
|
-
return React.createElement("span", null, this.props.onEvent());
|
67
|
-
}
|
68
|
-
})
|
69
|
-
}
|
70
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
71
|
-
Foo.class_eval do
|
72
|
-
imports "NativeComponent"
|
73
|
-
end
|
74
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo).on(:event) {'works!'})).to eq('<span>works!</span>')
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'will subscribe to a component event param with a non-default name' do
|
78
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
79
|
-
Foo.class_eval do
|
80
|
-
param :my_event, type: Proc, default: nil, allow_nil: true
|
81
|
-
def render
|
82
|
-
params.my_event
|
83
|
-
end
|
84
|
-
end
|
85
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo).on("<my_event>") {'works!'})).to eq('<span>works!</span>')
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'will subscribe to a component event param using the deprecated naming convention and generate a message' do
|
89
|
-
stub_const 'Foo', Class.new(React::Component::Base)
|
90
|
-
Foo.class_eval do
|
91
|
-
param :_onEvent, type: Proc, default: nil, allow_nil: true
|
92
|
-
def render
|
93
|
-
params._onEvent
|
94
|
-
end
|
95
|
-
end
|
96
|
-
%x{
|
97
|
-
var log = [];
|
98
|
-
var org_warn_console = window.console.warn;
|
99
|
-
var org_error_console = window.console.error;
|
100
|
-
window.console.warn = window.console.error = function(str){log.push(str)}
|
101
|
-
}
|
102
|
-
expect(React::Server.render_to_static_markup(React.create_element(Foo).on(:event) {'works!'})).to eq('<span>works!</span>')
|
103
|
-
`window.console.warn = org_warn_console; window.console.error = org_error_console;`
|
104
|
-
expect(`log[0]`).to match(/Warning: Failed prop( type|Type): In component `Foo`\nProvided prop `on_event` not specified in spec/)
|
105
|
-
expect(`log[1]`).to eq("Warning: Deprecated feature used in Foo. In future releases React::Element#on('event') will no longer respond to the '_onEvent' emitter.\nRename your emitter param to 'on_event' or use .on('<_onEvent>')")
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe 'Builtin Event subscription' do
|
110
|
-
it 'is subscribable through `on(:event_name)` method' do
|
111
|
-
expect { |b|
|
112
|
-
element = React.create_element("div").on(:click, &b)
|
113
|
-
dom_node = React::Test::Utils.render_into_document(element)
|
114
|
-
React::Test::Utils.simulate(:click, dom_node)
|
115
|
-
}.to yield_with_args(React::Event)
|
116
|
-
|
117
|
-
expect { |b|
|
118
|
-
element = React.create_element("div").on(:key_down, &b)
|
119
|
-
dom_node = React::Test::Utils.render_into_document(element)
|
120
|
-
React::Test::Utils.simulate(:keyDown, dom_node, {key: "Enter"})
|
121
|
-
}.to yield_control
|
122
|
-
|
123
|
-
expect { |b|
|
124
|
-
element = React.create_element("form").on(:submit, &b)
|
125
|
-
dom_node = React::Test::Utils.render_into_document(element)
|
126
|
-
React::Test::Utils.simulate(:submit, dom_node)
|
127
|
-
}.to yield_control
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'returns self for `on` method' do
|
131
|
-
element = React.create_element("div")
|
132
|
-
expect(element.on(:click){}).to eq(element)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
data/spec/react/event_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
describe React::Event do
|
5
|
-
it "should bridge attributes of native SyntheticEvent (see http://facebook.github.io/react/docs/events.html#syntheticevent)" do
|
6
|
-
element = React.create_element('div').on(:click) do |event|
|
7
|
-
expect(event.bubbles).to eq(`#{event.to_n}.bubbles`)
|
8
|
-
expect(event.cancelable).to eq(`#{event.to_n}.cancelable`)
|
9
|
-
expect(event.current_target).to eq(`#{event.to_n}.currentTarget`)
|
10
|
-
expect(event.default_prevented).to eq(`#{event.to_n}.defaultPrevented`)
|
11
|
-
expect(event.event_phase).to eq(`#{event.to_n}.eventPhase`)
|
12
|
-
expect(event.is_trusted?).to eq(`#{event.to_n}.isTrusted`)
|
13
|
-
expect(event.native_event).to eq(`#{event.to_n}.nativeEvent`)
|
14
|
-
expect(event.target).to eq(`#{event.to_n}.target`)
|
15
|
-
expect(event.timestamp).to eq(`#{event.to_n}.timeStamp`)
|
16
|
-
expect(event.event_type).to eq(`#{event.to_n}.type`)
|
17
|
-
expect(event).to respond_to(:prevent_default)
|
18
|
-
expect(event).to respond_to(:stop_propagation)
|
19
|
-
end
|
20
|
-
dom_node = React::Test::Utils.render_into_document(element)
|
21
|
-
React::Test::Utils.simulate(:click, dom_node)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|