hyper-react 1.0.0.lap27 → 1.0.0.lap28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 370cae4fc7839992e12c643e371aaee4db92c9bd1362d717a3573b1034445467
4
- data.tar.gz: b60a9208f2df241fa515d01b0fae10a231c07b7a03614160bc7eaea6785cfe40
3
+ metadata.gz: d9576218218234fed776182c5bd4814d2214d0bccb8102713c9dfcb5c02896f7
4
+ data.tar.gz: 2459b76e64f90a64ebae1d995b823b9518eec3a3a11344f49f370506cebe9796
5
5
  SHA512:
6
- metadata.gz: a8b4ddcfa119efc40385d306013afebf962f0d4fe8a52b29ba8a390cf8f0a6e1bc98951cc1fdf2dbed1c4b050793a16ab6ca137f97d4eca92507f010e822b45d
7
- data.tar.gz: f98141b845788eab333e4881694a02d3435e471d2ef2654312ad873b757a1d4f44e19e91bdb51b8fcdb64cc0f7753279669f5b5435606f83103423a303f23a53
6
+ metadata.gz: aef37ff1d4521bde8476c00f98b312c17f72db9a36694dd7a3427d17dcc8572205cd2524c53a1e312e8250c18f8341d384dab85e0bb43fff86197a0980de1a02
7
+ data.tar.gz: d39a312fe4ba268ca680411ff37c6ee981501c4cccc382d432387e2fd31d486e2e2aa8e01b1743b43c7af846e5631c68c602e8364c1a58b4f13a697de947284b
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  # }
19
19
 
20
20
  spec.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(gemfiles|spec)/}) }
21
- spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
21
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
22
  spec.require_paths = ['lib']
24
23
 
@@ -26,6 +25,8 @@ Gem::Specification.new do |spec|
26
25
  spec.add_dependency 'opal', '>= 0.11.0', '< 0.12.0'
27
26
  spec.add_dependency 'opal-activesupport', '~> 0.3.1'
28
27
  spec.add_dependency 'hyperloop-config', React::VERSION
28
+ spec.add_dependency 'mini_racer', '~> 0.1.15'
29
+ spec.add_dependency 'react-rails', '>= 2.4.0', '< 2.5.0'
29
30
 
30
31
  spec.add_development_dependency 'chromedriver-helper'
31
32
  spec.add_development_dependency 'hyper-spec', React::VERSION
@@ -36,13 +37,13 @@ Gem::Specification.new do |spec|
36
37
  spec.add_development_dependency 'opal-jquery'
37
38
  spec.add_development_dependency 'opal-rails', '~> 0.9.4'
38
39
  spec.add_development_dependency 'opal-rspec'
40
+ spec.add_development_dependency 'puma'
41
+ spec.add_development_dependency 'pry'
39
42
  spec.add_development_dependency 'rails', '>= 4.0.0'
40
43
  spec.add_development_dependency 'rails-controller-testing'
41
44
  spec.add_development_dependency 'rake'
42
- spec.add_development_dependency 'react-rails', '>= 2.4.0', '< 2.5.0'
43
45
  spec.add_development_dependency 'rspec-rails'
44
46
  spec.add_development_dependency 'rubocop', '~> 0.51.0'
45
47
  spec.add_development_dependency 'sqlite3'
46
- spec.add_development_dependency 'mini_racer', '~> 0.1.15'
47
48
  spec.add_development_dependency 'timecop', '~> 0.8.1'
48
49
  end
@@ -39,6 +39,7 @@ if RUBY_ENGINE == 'opal'
39
39
  require 'react/rendering_context'
40
40
  require 'react/state'
41
41
  require 'react/object'
42
+ require 'react/to_key'
42
43
  require 'react/ext/opal-jquery/element'
43
44
  require 'reactive-ruby/isomorphic_helpers'
44
45
  require 'rails-helpers/top_level_rails_component'
@@ -56,9 +56,17 @@ module React
56
56
  this.__opalInstance = #{type.new(`this`)};
57
57
  this.__opalInstanceInitializedState = true;
58
58
  this.__opalInstanceSyncSetState = false;
59
+ this.__name = #{type.name};
59
60
  }
60
61
  static get displayName() {
61
- return #{type.name};
62
+ if (typeof this.__name != "undefined") {
63
+ return this.__name;
64
+ } else {
65
+ return #{type.name};
66
+ }
67
+ }
68
+ static set displayName(name) {
69
+ this.__name = name;
62
70
  }
63
71
  static get defaultProps() {
64
72
  return #{type.respond_to?(:default_props) ? type.default_props.to_n : `{}`};
@@ -106,11 +114,11 @@ module React
106
114
  }
107
115
  }
108
116
  componentWillUnmount() {
109
- this.__opalInstance.is_mounted = false;
110
117
  if (#{type.method_defined? :component_will_unmount}) {
111
118
  this.__opalInstanceSyncSetState = false;
112
119
  this.__opalInstance.$component_will_unmount();
113
120
  }
121
+ this.__opalInstance.is_mounted = false;
114
122
  }
115
123
  componentDidCatch(error, info) {
116
124
  if (#{type.method_defined? :component_did_catch}) {
@@ -11,6 +11,7 @@ module React
11
11
 
12
12
  def force_update!
13
13
  `#{self}.native.forceUpdate()`
14
+ self
14
15
  end
15
16
 
16
17
  def set_props(prop, &block)
@@ -32,15 +33,15 @@ module React
32
33
  def set_or_replace_state_or_prop(state_or_prop, method, &block)
33
34
  raise "No native ReactComponent associated" unless @native
34
35
  `var state_prop_n = #{state_or_prop.shallow_to_n}`
35
- # the state object is initalized when the ruby component is instanciated
36
+ # the state object is initalized when the ruby component is instantiated
36
37
  # this is detected by self.native.__opalInstanceInitializedState
37
- # which is set in the netive component constructor in react/api.rb
38
+ # which is set in the native component constructor in react/api.rb
38
39
  # the setState update callback is not called when initalizing initial state
39
40
  if block
40
41
  %x{
41
42
  if (#{@native}.__opalInstanceInitializedState === true) {
42
43
  #{@native}[method](state_prop_n, function(){
43
- #{block.call}
44
+ block.$call();
44
45
  });
45
46
  } else {
46
47
  for (var sp in state_prop_n) {
@@ -130,8 +130,17 @@ module React
130
130
  def merge_built_in_event_prop!(prop_name)
131
131
  @properties.merge!(
132
132
  prop_name => %x{
133
- function(event){
134
- return #{yield(React::Event.new(`event`))}
133
+ function(){
134
+ var react_event = arguments[0];
135
+ var all_args;
136
+ var other_args;
137
+ if (arguments.length > 1) {
138
+ all_args = Array.prototype.slice.call(arguments);
139
+ other_args = all_args.slice(1, arguments.length);
140
+ return #{yield(React::Event.new(`react_event`), *(`other_args`))};
141
+ } else {
142
+ return #{yield(React::Event.new(`react_event`))};
143
+ }
135
144
  }
136
145
  }
137
146
  )
@@ -23,4 +23,15 @@ Element.instance_eval do
23
23
 
24
24
  React.render(React.create_element(`#{self.to_n}._reactrb_component_class`), self)
25
25
  end
26
+
27
+ # mount_components is useful for dynamically generated page segments for example
28
+ # see react-rails documentation for more details
29
+
30
+ %x{
31
+ $.fn.mount_components = function() {
32
+ this.each(function(e) { ReactRailsUJS.mountComponents(e[0]) })
33
+ return this;
34
+ }
35
+ }
36
+ Element.expose :mount_components
26
37
  end if Object.const_defined?('Element')
@@ -12,20 +12,4 @@ class Object
12
12
  React::Component::Tags.html_tag_class_for(const_name) || raise(e)
13
13
  end
14
14
  end
15
-
16
- def to_key
17
- object_id
18
- end
19
- end
20
-
21
- class Number
22
- def to_key
23
- self
24
- end
25
- end
26
-
27
- class Boolean
28
- def to_key
29
- self
30
- end
31
15
  end
@@ -0,0 +1,26 @@
1
+ # to_key method returns a suitable unique id that can be used as
2
+ # a react `key`. Other classes may override to_key as needed
3
+ # for example hyper_mesh returns the object id of the internal
4
+ # backing record.
5
+ #
6
+ # to_key is automatically called on objects passed as keys for
7
+ # example Foo(key: my_object) results in Foo(key: my_object.to_key)
8
+ class Object
9
+ def to_key
10
+ object_id
11
+ end
12
+ end
13
+
14
+ # for Number to_key can just be the number itself
15
+ class Number
16
+ def to_key
17
+ self
18
+ end
19
+ end
20
+
21
+ # for Boolean to_key can be true or false
22
+ class Boolean
23
+ def to_key
24
+ self
25
+ end
26
+ end
@@ -12,9 +12,9 @@ module ReactiveRuby
12
12
  options = context_initializer_options(options, name)
13
13
  end
14
14
  props = serialized_props(props, name, controller)
15
- super(top_level_name, props, options, &block).gsub("\n","")
16
- .gsub(/(<script>.*<\/script>)<\/div>$/,'</div>\1').html_safe +
17
- footers
15
+ result = super(top_level_name, props, options, &block).gsub("\n","")
16
+ result = result.gsub(/(<script.*<\/script>)<\/div>$/,'</div>\1').html_safe
17
+ result + footers
18
18
  end
19
19
 
20
20
  private
@@ -1,12 +1,20 @@
1
- [Bignum, FalseClass, Fixnum, Float, Integer, NilClass, String, Symbol, Time, TrueClass].each do |klass|
2
- klass.send(:define_method, :react_serializer) do
1
+ [FalseClass, Float, Integer, NilClass, String, Symbol, Time, TrueClass].each do |klass|
2
+ klass.send(:define_method, :react_serializer) do
3
3
  as_json
4
4
  end
5
5
  end
6
6
 
7
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4.0')
8
+ [Bignum, Fixnum].each do |klass|
9
+ klass.send(:define_method, :react_serializer) do
10
+ as_json
11
+ end
12
+ end
13
+ end
14
+
7
15
  BigDecimal.send(:define_method, :react_serializer) { as_json } rescue nil
8
16
 
9
- Array.send(:define_method, :react_serializer) do
17
+ Array.send(:define_method, :react_serializer) do
10
18
  self.collect { |e| e.react_serializer }.as_json
11
19
  end
12
20
 
@@ -14,6 +14,11 @@ module ReactiveRuby
14
14
  ComponentLoader.new(v8_context).load
15
15
  end
16
16
 
17
+ def before_render(*args)
18
+ # the base class clears the log history... we don't want that as it is taken
19
+ # care of in IsomorphicHelpers.load_context
20
+ end
21
+
17
22
  def render(component_name, props, prerender_options)
18
23
  if prerender_options.is_a?(Hash)
19
24
  if !v8_runtime? && prerender_options[:context_initializer]
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '1.0.0.lap27'
2
+ VERSION = '1.0.0.lap28'
3
3
  end
@@ -116,7 +116,7 @@ describe 'React::Component', js: true do
116
116
  def self.get_error
117
117
  @@error
118
118
  end
119
-
119
+
120
120
  def self.get_info
121
121
  @@info
122
122
  end
@@ -136,6 +136,48 @@ describe 'React::Component', js: true do
136
136
  end
137
137
  end
138
138
 
139
+ describe 'Misc Methods' do
140
+ it 'has a force_update! method' do
141
+ mount 'Foo' do
142
+ class Foo < Hyperloop::Component
143
+ class << self
144
+ attr_accessor :render_counter
145
+ attr_accessor :instance
146
+ end
147
+ before_mount do
148
+ Foo.render_counter = 0
149
+ Foo.instance = self
150
+ end
151
+ def render
152
+ Foo.render_counter += 1
153
+ DIV { "I have been rendered #{Foo.render_counter} times" }
154
+ end
155
+ end
156
+ end
157
+ expect_evaluate_ruby do
158
+ Foo.instance.force_update!
159
+ Foo.render_counter
160
+ end.to eq(2)
161
+ end
162
+
163
+ it 'has its force_update! method return itself' do
164
+ mount 'Foo' do
165
+ class Foo < Hyperloop::Component
166
+ class << self
167
+ attr_accessor :instance
168
+ end
169
+ before_mount do
170
+ Foo.instance = self
171
+ end
172
+ def render
173
+ DIV { "I have been rendered" }
174
+ end
175
+ end
176
+ end
177
+ expect_evaluate_ruby('Foo.instance == Foo.instance.force_update!').to be_truthy
178
+ end
179
+ end
180
+
139
181
  describe 'New style setter & getter' do
140
182
  before(:each) do
141
183
  on_client do
@@ -843,7 +885,6 @@ describe 'React::Component', js: true do
843
885
 
844
886
  it 'only overrides `p` in render context' do
845
887
  mount 'Foo' do
846
-
847
888
  class Foo
848
889
  include React::Component
849
890
 
@@ -103,7 +103,7 @@ describe 'the React DSL', js: true do
103
103
  end
104
104
  end
105
105
  end
106
- expect(page.body[-80..-19]).to match(/(<div data-reactroot=""|<div)><span>hello<(br|br\/|br \/)><\/span><\/div>/)
106
+ expect(page.body[-285..-233]).to match(/(<div data-reactroot=""|<div)><span>hello<(br|br\/|br \/)><\/span><\/div>/)
107
107
  end
108
108
 
109
109
  it "has a .td short hand String method" do
@@ -197,7 +197,7 @@ describe 'the React DSL', js: true do
197
197
  'raised for sure!'
198
198
  end
199
199
  end.to eq('raised for sure!')
200
-
200
+
201
201
  end
202
202
 
203
203
  it "will treat the component class name as a first class component name" do
@@ -28,7 +28,7 @@ describe 'React::Element', js: true do
28
28
  end
29
29
  end
30
30
  end
31
- expect(page.body[-80..-19]).to match(/<input (type="text" value=""|value="" type="text").*\/>/)
31
+ expect(page.body[-285..-233]).to match(/<input (type="text" value=""|value="" type="text").*\/>/)
32
32
  end
33
33
  end
34
34
 
@@ -62,7 +62,7 @@ describe 'React::Element', js: true do
62
62
  end
63
63
 
64
64
  it 'will subscribe to a native components event param' do
65
-
65
+
66
66
  evaluate_ruby do
67
67
  "this makes sure everything is loaded"
68
68
  end
@@ -84,7 +84,7 @@ describe 'React::Element', js: true do
84
84
  end
85
85
 
86
86
  it 'will subscribe to a component event param with a non-default name' do
87
-
87
+
88
88
  evaluate_ruby do
89
89
  class Foo < React::Component::Base
90
90
  param :my_event, type: Proc, default: nil, allow_nil: true
@@ -67,5 +67,28 @@ describe 'opal-jquery extensions', js: true do
67
67
  expect(page.driver.browser.manage.logs.get(:browser).map { |m| m.message.gsub(/\\n/, "\n") }.to_a.join("\n"))
68
68
  .not_to match(/Exception|Error/)
69
69
  end
70
+
71
+ it "can dynamically mount components" do
72
+ on_client do
73
+ class DynoMount < Hyperloop::Component
74
+ render(DIV) { 'I got rendered' }
75
+ end
76
+ end
77
+ mount 'MountPoint' do
78
+ class MountPoint < Hyperloop::Component
79
+ render(DIV) do
80
+ # simulate what react-rails render_component output
81
+ DIV(
82
+ 'data-react-class' => 'React.TopLevelRailsComponent',
83
+ 'data-react-props' => '{"render_params": {}, "component_name": "DynoMount", "controller": ""}'
84
+ )
85
+ end
86
+ end
87
+ end
88
+ evaluate_ruby do
89
+ Element['body'].mount_components
90
+ end
91
+ expect(page).to have_content('I got rendered')
92
+ end
70
93
  end
71
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.lap27
4
+ version: 1.0.0.lap28
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chang
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-03-07 00:00:00.000000000 Z
14
+ date: 2018-05-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: hyper-store
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 1.0.0.lap27
22
+ version: 1.0.0.lap28
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.0.0.lap27
29
+ version: 1.0.0.lap28
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: opal
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -67,14 +67,48 @@ dependencies:
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 1.0.0.lap27
70
+ version: 1.0.0.lap28
71
71
  type: :runtime
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 1.0.0.lap27
77
+ version: 1.0.0.lap28
78
+ - !ruby/object:Gem::Dependency
79
+ name: mini_racer
80
+ requirement: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 0.1.15
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: 0.1.15
92
+ - !ruby/object:Gem::Dependency
93
+ name: react-rails
94
+ requirement: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.4.0
99
+ - - "<"
100
+ - !ruby/object:Gem::Version
101
+ version: 2.5.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.4.0
109
+ - - "<"
110
+ - !ruby/object:Gem::Version
111
+ version: 2.5.0
78
112
  - !ruby/object:Gem::Dependency
79
113
  name: chromedriver-helper
80
114
  requirement: !ruby/object:Gem::Requirement
@@ -95,14 +129,14 @@ dependencies:
95
129
  requirements:
96
130
  - - '='
97
131
  - !ruby/object:Gem::Version
98
- version: 1.0.0.lap27
132
+ version: 1.0.0.lap28
99
133
  type: :development
100
134
  prerelease: false
101
135
  version_requirements: !ruby/object:Gem::Requirement
102
136
  requirements:
103
137
  - - '='
104
138
  - !ruby/object:Gem::Version
105
- version: 1.0.0.lap27
139
+ version: 1.0.0.lap28
106
140
  - !ruby/object:Gem::Dependency
107
141
  name: jquery-rails
108
142
  requirement: !ruby/object:Gem::Requirement
@@ -202,21 +236,21 @@ dependencies:
202
236
  - !ruby/object:Gem::Version
203
237
  version: '0'
204
238
  - !ruby/object:Gem::Dependency
205
- name: rails
239
+ name: puma
206
240
  requirement: !ruby/object:Gem::Requirement
207
241
  requirements:
208
242
  - - ">="
209
243
  - !ruby/object:Gem::Version
210
- version: 4.0.0
244
+ version: '0'
211
245
  type: :development
212
246
  prerelease: false
213
247
  version_requirements: !ruby/object:Gem::Requirement
214
248
  requirements:
215
249
  - - ">="
216
250
  - !ruby/object:Gem::Version
217
- version: 4.0.0
251
+ version: '0'
218
252
  - !ruby/object:Gem::Dependency
219
- name: rails-controller-testing
253
+ name: pry
220
254
  requirement: !ruby/object:Gem::Requirement
221
255
  requirements:
222
256
  - - ">="
@@ -230,7 +264,21 @@ dependencies:
230
264
  - !ruby/object:Gem::Version
231
265
  version: '0'
232
266
  - !ruby/object:Gem::Dependency
233
- name: rake
267
+ name: rails
268
+ requirement: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - ">="
271
+ - !ruby/object:Gem::Version
272
+ version: 4.0.0
273
+ type: :development
274
+ prerelease: false
275
+ version_requirements: !ruby/object:Gem::Requirement
276
+ requirements:
277
+ - - ">="
278
+ - !ruby/object:Gem::Version
279
+ version: 4.0.0
280
+ - !ruby/object:Gem::Dependency
281
+ name: rails-controller-testing
234
282
  requirement: !ruby/object:Gem::Requirement
235
283
  requirements:
236
284
  - - ">="
@@ -244,25 +292,19 @@ dependencies:
244
292
  - !ruby/object:Gem::Version
245
293
  version: '0'
246
294
  - !ruby/object:Gem::Dependency
247
- name: react-rails
295
+ name: rake
248
296
  requirement: !ruby/object:Gem::Requirement
249
297
  requirements:
250
298
  - - ">="
251
299
  - !ruby/object:Gem::Version
252
- version: 2.4.0
253
- - - "<"
254
- - !ruby/object:Gem::Version
255
- version: 2.5.0
300
+ version: '0'
256
301
  type: :development
257
302
  prerelease: false
258
303
  version_requirements: !ruby/object:Gem::Requirement
259
304
  requirements:
260
305
  - - ">="
261
306
  - !ruby/object:Gem::Version
262
- version: 2.4.0
263
- - - "<"
264
- - !ruby/object:Gem::Version
265
- version: 2.5.0
307
+ version: '0'
266
308
  - !ruby/object:Gem::Dependency
267
309
  name: rspec-rails
268
310
  requirement: !ruby/object:Gem::Requirement
@@ -305,20 +347,6 @@ dependencies:
305
347
  - - ">="
306
348
  - !ruby/object:Gem::Version
307
349
  version: '0'
308
- - !ruby/object:Gem::Dependency
309
- name: mini_racer
310
- requirement: !ruby/object:Gem::Requirement
311
- requirements:
312
- - - "~>"
313
- - !ruby/object:Gem::Version
314
- version: 0.1.15
315
- type: :development
316
- prerelease: false
317
- version_requirements: !ruby/object:Gem::Requirement
318
- requirements:
319
- - - "~>"
320
- - !ruby/object:Gem::Version
321
- version: 0.1.15
322
350
  - !ruby/object:Gem::Dependency
323
351
  name: timecop
324
352
  requirement: !ruby/object:Gem::Requirement
@@ -401,6 +429,7 @@ files:
401
429
  - lib/react/test/rspec.rb
402
430
  - lib/react/test/session.rb
403
431
  - lib/react/test/utils.rb
432
+ - lib/react/to_key.rb
404
433
  - lib/react/top_level.rb
405
434
  - lib/react/top_level_render.rb
406
435
  - lib/react/validator.rb
@@ -540,7 +569,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
540
569
  version: 1.3.1
541
570
  requirements: []
542
571
  rubyforge_project:
543
- rubygems_version: 2.7.3
572
+ rubygems_version: 2.7.6
544
573
  signing_key:
545
574
  specification_version: 4
546
575
  summary: Opal Ruby wrapper of React.js library.