hyper-component 1.0.alpha1.2 → 1.0.alpha1.3

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: 32f892af1c88068a155f6a7de78fe37ec32f157fe6e3e20d1a06db63501a43af
4
- data.tar.gz: 031e39966cb44433d836a82e563236b985b59def309a9bfb39107ac1cc151e08
3
+ metadata.gz: 42dc80deeb92bd2de37632efacae8b8d4a801c530d65937b7535018a2d3bc91a
4
+ data.tar.gz: 142a8df3b61e46f55d0d56766cddff7e734fc01b5f7f594ea6a57900bc4e9e4c
5
5
  SHA512:
6
- metadata.gz: 0ef39af06f446589c0b2ce1137d0403d0125c21657b857e7c3785921c800e9aaa1cb2975cd06e104de4bb45612bc510b0b3fe8ba0233dc68902b2d877bb1d430
7
- data.tar.gz: b3a8f74fecb413e0fa82eb7ce97de80123b7e67fd9da9b3a5d9bff2d6a7f287f03aad6a8b62703cb776b14fa0233c602964ca20e56d9225a774be11e59bae9c8
6
+ metadata.gz: 5306b0fd124bee54d7873b2b6a0f4d6713fd346e2efa3bf9ba9f0467df1348a919daf07aecedb55983e26f95076f8df67981774c3288d6eda3af346036fea791
7
+ data.tar.gz: ea657f7f9aae7884b5602f3be778452f9088bf9a34ca2afef10ce98e10428412a2e53d5dad6abf55a65f7edc2041460b598b5bd12c6422cb608a29423b8d12ee
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: ../hyper-spec
3
3
  specs:
4
- hyper-spec (1.0.alpha1.2)
4
+ hyper-spec (1.0.alpha1.3)
5
5
  capybara
6
6
  chromedriver-helper (= 1.2.0)
7
- libv8 (~> 6.3.0)
7
+ libv8
8
8
  method_source
9
- mini_racer (~> 0.1.15)
9
+ mini_racer (~> 0.2.4)
10
10
  opal (>= 0.11.0, < 0.12.0)
11
11
  parser (>= 2.3.3.1)
12
12
  pry
@@ -14,31 +14,30 @@ PATH
14
14
  selenium-webdriver
15
15
  timecop (~> 0.8.1)
16
16
  uglifier
17
- unparser
17
+ unparser (>= 0.2, < 0.4)
18
18
  webdrivers
19
19
 
20
20
  PATH
21
21
  remote: ../hyper-state
22
22
  specs:
23
- hyper-state (1.0.alpha1.2)
24
- hyperstack-config (= 1.0.alpha1.2)
23
+ hyper-state (1.0.alpha1.3)
24
+ hyperstack-config (= 1.0.alpha1.3)
25
25
  opal (>= 0.11.0, < 0.12.0)
26
26
 
27
27
  PATH
28
28
  remote: ../hyper-store
29
29
  specs:
30
- hyper-store (1.0.alpha1.2)
31
- hyper-state (= 1.0.alpha1.2)
32
- hyperstack-config (= 1.0.alpha1.2)
30
+ hyper-store (1.0.alpha1.3)
31
+ hyper-state (= 1.0.alpha1.3)
32
+ hyperstack-config (= 1.0.alpha1.3)
33
33
  opal (>= 0.11.0, < 0.12.0)
34
34
 
35
35
  PATH
36
36
  remote: ../hyperstack-config
37
37
  specs:
38
- hyperstack-config (1.0.alpha1.2)
39
- libv8 (~> 6.3.0)
38
+ hyperstack-config (1.0.alpha1.3)
40
39
  listen (~> 3.0)
41
- mini_racer (~> 0.1.15)
40
+ mini_racer (~> 0.2.4)
42
41
  opal (>= 0.11.0, < 0.12.0)
43
42
  opal-browser (~> 0.2.0)
44
43
  uglifier
@@ -47,11 +46,11 @@ PATH
47
46
  PATH
48
47
  remote: .
49
48
  specs:
50
- hyper-component (1.0.alpha1.2)
51
- hyper-state (= 1.0.alpha1.2)
52
- hyperstack-config (= 1.0.alpha1.2)
53
- libv8 (~> 6.3.0)
54
- mini_racer (~> 0.1.15)
49
+ hyper-component (1.0.alpha1.3)
50
+ hyper-state (= 1.0.alpha1.3)
51
+ hyperstack-config (= 1.0.alpha1.3)
52
+ libv8 (~> 6.7.0)
53
+ mini_racer (~> 0.2.4)
55
54
  opal (>= 0.11.0, < 0.12.0)
56
55
  opal-activesupport (~> 0.3.1)
57
56
  react-rails (>= 2.4.0, < 2.5.0)
@@ -115,7 +114,7 @@ GEM
115
114
  babel-source (>= 4.0, < 6)
116
115
  execjs (~> 2.0)
117
116
  builder (3.2.3)
118
- capybara (3.11.0)
117
+ capybara (3.12.0)
119
118
  addressable
120
119
  mini_mime (>= 0.1.3)
121
120
  nokogiri (~> 1.8)
@@ -152,7 +151,7 @@ GEM
152
151
  rails-dom-testing (>= 1, < 3)
153
152
  railties (>= 4.2.0)
154
153
  thor (>= 0.14, < 2.0)
155
- libv8 (6.3.292.48.1)
154
+ libv8 (6.7.288.46.1)
156
155
  listen (3.1.5)
157
156
  rb-fsevent (~> 0.9, >= 0.9.4)
158
157
  rb-inotify (~> 0.9, >= 0.9.7)
@@ -173,9 +172,10 @@ GEM
173
172
  mimemagic (0.3.2)
174
173
  mini_mime (1.0.1)
175
174
  mini_portile2 (2.3.0)
176
- mini_racer (0.1.15)
177
- libv8 (~> 6.3)
175
+ mini_racer (0.2.4)
176
+ libv8 (>= 6.3)
178
177
  minitest (5.11.3)
178
+ net_http_ssl_fix (0.0.10)
179
179
  nio4r (2.3.1)
180
180
  nokogiri (1.8.5)
181
181
  mini_portile2 (~> 2.3.0)
@@ -308,7 +308,7 @@ GEM
308
308
  timecop (0.8.1)
309
309
  tzinfo (1.2.5)
310
310
  thread_safe (~> 0.1)
311
- uglifier (4.1.19)
311
+ uglifier (4.1.20)
312
312
  execjs (>= 0.3.0, < 3)
313
313
  unicode-display_width (1.4.0)
314
314
  unparser (0.2.8)
@@ -319,7 +319,8 @@ GEM
319
319
  equalizer (~> 0.0.9)
320
320
  parser (>= 2.3.1.2, < 2.6)
321
321
  procto (~> 0.0.2)
322
- webdrivers (3.4.3)
322
+ webdrivers (3.6.0)
323
+ net_http_ssl_fix
323
324
  nokogiri (~> 1.6)
324
325
  rubyzip (~> 1.0)
325
326
  selenium-webdriver (~> 3.0)
@@ -334,7 +335,7 @@ PLATFORMS
334
335
  ruby
335
336
 
336
337
  DEPENDENCIES
337
- bundler (~> 1.16.0)
338
+ bundler (>= 1.17.3, < 2.1)
338
339
  chromedriver-helper
339
340
  hyper-component!
340
341
  hyper-spec!
@@ -360,4 +361,4 @@ DEPENDENCIES
360
361
  timecop (~> 0.8.1)
361
362
 
362
363
  BUNDLED WITH
363
- 1.16.1
364
+ 2.0.1
@@ -23,13 +23,13 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency 'hyper-state', Hyperstack::Component::VERSION
25
25
  spec.add_dependency 'hyperstack-config', Hyperstack::Component::VERSION
26
- spec.add_dependency 'libv8', '~> 6.3.0' # see https://github.com/discourse/mini_racer/issues/92
27
- spec.add_dependency 'mini_racer', '~> 0.1.15'
26
+ spec.add_dependency 'libv8', '~> 6.7.0'
27
+ spec.add_dependency 'mini_racer', '~> 0.2.4'
28
28
  spec.add_dependency 'opal', '>= 0.11.0', '< 0.12.0'
29
29
  spec.add_dependency 'opal-activesupport', '~> 0.3.1'
30
30
  spec.add_dependency 'react-rails', '>= 2.4.0', '< 2.5.0'
31
31
 
32
- spec.add_development_dependency 'bundler', '~> 1.16.0'
32
+ spec.add_development_dependency 'bundler', ['>= 1.17.3', '< 2.1']
33
33
  spec.add_development_dependency 'chromedriver-helper'
34
34
  spec.add_development_dependency 'hyper-spec', Hyperstack::Component::VERSION
35
35
  spec.add_development_dependency 'jquery-rails'
@@ -27,6 +27,10 @@ if RUBY_ENGINE == 'opal'
27
27
  require 'hyperstack/component/isomorphic_helpers'
28
28
  require 'hyperstack/component/react_api'
29
29
  require 'hyperstack/internal/component/top_level_rails_component'
30
+ require 'hyperstack/component/while_loading'
31
+ require 'hyperstack/internal/component/rescue_wrapper'
32
+ require 'hyperstack/internal/component/while_loading_wrapper'
33
+
30
34
  require 'hyperstack/component/version'
31
35
  else
32
36
  require 'opal'
@@ -21,9 +21,11 @@ module Hyperstack
21
21
  class_attribute :initial_state
22
22
  define_callback :before_mount
23
23
  define_callback :after_mount
24
- define_callback :before_receive_props
24
+ define_callback :before_new_params
25
25
  define_callback :before_update
26
26
  define_callback :after_update
27
+ define_callback :__hyperstack_component_after_render_hook
28
+ define_callback :__hyperstack_component_rescue_hook
27
29
  #define_callback :before_unmount defined already by Async module
28
30
  define_callback(:after_error) { Hyperstack::Internal::Component::ReactWrapper.add_after_error_hook(base) }
29
31
  end
@@ -93,13 +95,14 @@ module Hyperstack
93
95
  def component_did_mount
94
96
  observing(update_objects: true) do
95
97
  run_callback(:after_mount)
98
+ Hyperstack::Internal::Component::RenderingContext.quiet_test(self)
96
99
  end
97
100
  end
98
101
 
99
102
  def component_will_receive_props(next_props)
100
103
  # need to rethink how this works in opal-react, or if its actually that useful within the react.rb environment
101
104
  # for now we are just using it to clear processed_params
102
- observing(immediate_update: true) { run_callback(:before_receive_props, next_props) }
105
+ observing(immediate_update: true) { run_callback(:before_new_params, next_props) }
103
106
  @__hyperstack_component_receiving_props = true
104
107
  end
105
108
 
@@ -112,7 +115,10 @@ module Hyperstack
112
115
  end
113
116
 
114
117
  def component_did_update(prev_props, prev_state)
115
- observing(update_objects: true) { run_callback(:after_update, prev_props, prev_state) }
118
+ observing(update_objects: true) do
119
+ run_callback(:after_update, prev_props, prev_state)
120
+ Hyperstack::Internal::Component::RenderingContext.quiet_test(self)
121
+ end
116
122
  end
117
123
 
118
124
  def component_will_unmount
@@ -124,7 +130,9 @@ module Hyperstack
124
130
  end
125
131
 
126
132
  def component_did_catch(error, info)
127
- observing { run_callback(:after_error, error, info) }
133
+ observing do
134
+ run_callback(:after_error, error, info)
135
+ end
128
136
  end
129
137
 
130
138
  def mutations(_objects)
@@ -156,9 +164,15 @@ module Hyperstack
156
164
  @__hyperstack_component_waiting_on_resources
157
165
  end
158
166
 
167
+ def __hyperstack_component_run_post_render_hooks(element)
168
+ run_callback(:__hyperstack_component_after_render_hook, element) { |*args| args }.first
169
+ end
170
+
159
171
  def _render_wrapper
160
172
  observing(rendering: true) do
161
- element = Hyperstack::Internal::Component::RenderingContext.render(nil) { render || '' }
173
+ element = Hyperstack::Internal::Component::RenderingContext.render(nil) do
174
+ render || ''
175
+ end
162
176
  @__hyperstack_component_waiting_on_resources =
163
177
  element.waiting_on_resources if element.respond_to? :waiting_on_resources
164
178
  element
@@ -45,7 +45,7 @@ module Hyperstack
45
45
  # Used for elements that are not yet in DOM, i.e. they are provided as children
46
46
  # or they have been explicitly removed from the rendering context using the delete method.
47
47
 
48
- def render(props = {}, &new_block)
48
+ def render(*props, &new_block)
49
49
  if props.empty?
50
50
  Hyperstack::Internal::Component::RenderingContext.render(self)
51
51
  else
@@ -1,5 +1,5 @@
1
1
  module Hyperstack
2
2
  module Component
3
- VERSION = '1.0.alpha1.2' # '1.0.alpha1.2'
3
+ VERSION = '1.0.alpha1.3' # '1.0.alpha1.3'
4
4
  end
5
5
  end
@@ -0,0 +1,27 @@
1
+ module Hyperstack
2
+ module Component
3
+ module WhileLoading
4
+ def __hyperstack_component_rescue_wrapper(child)
5
+ Hyperstack::Internal::Component::WhileLoadingWrapper(child: self, children_elements: child)
6
+ end
7
+
8
+ def resources_loading?
9
+ @__hyperstack_while_loading_waiting_on_resources
10
+ end
11
+
12
+ def resources_loaded?
13
+ !@__hyperstack_while_loading_waiting_on_resources
14
+ end
15
+
16
+ if Hyperstack::Component::IsomorphicHelpers.on_opal_client?
17
+ %x{
18
+ function onError(event) {
19
+ if (event.message.startsWith('Uncaught NotQuiet: ')) event.preventDefault();
20
+ }
21
+
22
+ window.addEventListener('error', onError);
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -45,4 +45,20 @@ Element.instance_eval do
45
45
  Element.expose :mount_components
46
46
  end
47
47
 
48
- DOM = Element
48
+ module Hyperstack
49
+ module Internal
50
+ module Component
51
+ module InstanceMethods
52
+ def set_jq(var)
53
+ ->(val) { set(var).call(jQ[val]) }
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ class Object
61
+ def jQ
62
+ Element
63
+ end
64
+ end
@@ -5,4 +5,4 @@ class String
5
5
  return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
6
6
  })`
7
7
  end
8
- end
8
+ end
@@ -1,7 +1,13 @@
1
1
  require 'hyperstack-config'
2
2
 
3
3
  module Hyperstack
4
-
5
4
  define_setting :prerendering, :off if RUBY_ENGINE != 'opal'
6
5
 
6
+ module Internal
7
+ module Component
8
+ class << self
9
+ attr_accessor :after_error_args
10
+ end
11
+ end
12
+ end
7
13
  end
@@ -42,18 +42,74 @@ module Hyperstack
42
42
  backtrace[1..-1].each { |line| message_array << line }
43
43
  end
44
44
 
45
+ def before_receive_props(*args, &block)
46
+ deprecation_warning "'before_receive_props' is deprecated. Use the 'before_new_params' macro instead."
47
+ before_new_params(*args, &block)
48
+ end
49
+
45
50
  def render(container = nil, params = {}, &block)
46
51
  Tags.included(self)
47
52
  if container
48
53
  container = container.type if container.is_a? Hyperstack::Component::Element
49
- define_method :__hyperstack_component_render do
50
- RenderingContext.render(container, params) { instance_eval(&block) if block }
54
+ define_method(:__hyperstack_component_render) do
55
+ __hyperstack_component_select_wrappers do
56
+ RenderingContext.render(container, params) do
57
+ instance_eval(&block) if block
58
+ end
59
+ end
51
60
  end
52
61
  else
53
- define_method(:__hyperstack_component_render) { instance_eval(&block) }
62
+ define_method(:__hyperstack_component_render) do
63
+ __hyperstack_component_select_wrappers do
64
+ instance_eval(&block)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ # def while_loading(*args, &block)
71
+ # __hyperstack_component_after_render_hook do |element|
72
+ # element.while_loading(*args) { |*aargs| instance_exec(*aargs, &block) }
73
+ # end
74
+ # end
75
+
76
+ def on(*args, &block)
77
+ __hyperstack_component_after_render_hook do |element|
78
+ element.on(*args) { |*aargs| instance_exec(*aargs, &block) }
79
+ end
80
+ end
81
+
82
+ def rescues(*klasses, &block)
83
+ klasses = [StandardError] if klasses.empty?
84
+ __hyperstack_component_rescue_hook do |found, *args|
85
+ next [found, *args] if found || !klasses.detect { |klass| args[0].is_a? klass }
86
+ instance_exec(*args, &block)
87
+ [true, *args]
54
88
  end
55
89
  end
56
90
 
91
+ def before_render(*args, &block)
92
+ before_mount(*args, &block)
93
+ before_update(*args, &block)
94
+ end
95
+
96
+ def after_render(*args, &block)
97
+ after_mount(*args, &block)
98
+ after_update(*args, &block)
99
+ end
100
+
101
+ # [:while_loading, :on].each do |method|
102
+ # define_method(method) do |*args, &block|
103
+ # @@alias_id ||= 0
104
+ # @@alias_id += 1
105
+ # alias_name = "__hyperstack_attach_post_render_hook_#{@@alias_id}"
106
+ # alias_method alias_name, :__hyperstack_attach_post_render_hook
107
+ # define_method(:__hyperstack_attach_post_render_hook) do |element|
108
+ # send(alias_name, element.while_loading(*args) { instance_eval(&block) })
109
+ # end
110
+ # end
111
+ # end
112
+
57
113
  # method missing will assume the method is a class name, and will treat this a render of
58
114
  # of the component, i.e. Foo::Bar.baz === Foo::Bar().baz
59
115
 
@@ -147,8 +203,10 @@ module Hyperstack
147
203
 
148
204
  alias other_params collect_other_params_as
149
205
  alias others collect_other_params_as
206
+ alias other collect_other_params_as
207
+ alias opts collect_other_params_as
150
208
 
151
- def triggers(name, opts = {})
209
+ def fires(name, opts = {})
152
210
  aka = opts[:alias] || "#{name}!"
153
211
  name = if name =~ /^<(.+)>$/
154
212
  name.gsub(/^<(.+)>$/, '\1')
@@ -161,6 +219,8 @@ module Hyperstack
161
219
  define_method(aka) { |*args| props[name]&.call(*args) }
162
220
  end
163
221
 
222
+ alias triggers fires
223
+
164
224
  def define_state(*states, &block)
165
225
  deprecation_warning "'define_state' is deprecated. Use the 'state' macro to declare states."
166
226
  default_initial_value = (block && block.arity == 0) ? yield : nil
@@ -9,7 +9,7 @@ module Hyperstack
9
9
  end
10
10
 
11
11
  def params
12
- if @__hyperstack_component_params_wrapper.param_accessor_style == :hyperstack
12
+ if [:hyperstack, :accessors].include? @__hyperstack_component_params_wrapper.param_accessor_style
13
13
  raise "params are now directly accessible via instance variables.\n"\
14
14
  ' to access the legacy behavior add `param_accessor_style = :legacy` '\
15
15
  "to your component class\n"\
@@ -27,10 +27,24 @@ module Hyperstack
27
27
  `ReactDOM.findDOMNode(#{self}.__hyperstack_component_native)` # react >= v0.15.0
28
28
  end
29
29
 
30
+ def jq_node
31
+ ::Element[dom_node]
32
+ end
33
+
30
34
  def mounted?
31
35
  `(#{self}.__hyperstack_component_is_mounted === undefined) ? false : #{self}.__hyperstack_component_is_mounted`
32
36
  end
33
37
 
38
+ def pluralize(count, singular, plural = nil)
39
+ word = if (count == 1 || count =~ /^1(\.0+)?$/)
40
+ singular
41
+ else
42
+ plural || singular.pluralize
43
+ end
44
+
45
+ "#{count || 0} #{word}"
46
+ end
47
+
34
48
  def force_update!
35
49
  `#{self}.__hyperstack_component_native.forceUpdate()`
36
50
  self
@@ -47,6 +61,29 @@ module Hyperstack
47
61
 
48
62
  private
49
63
 
64
+ # can be overriden by the Router include
65
+ def __hyperstack_router_wrapper(&block)
66
+ ->() { instance_eval(&block) }
67
+ end
68
+
69
+ # can be overriden by including WhileLoading include
70
+ def __hyperstack_component_rescue_wrapper(child)
71
+ if self.class.callbacks?(:__hyperstack_component_rescue_hook)
72
+ Hyperstack::Internal::Component::RescueWrapper(child: self, children_elements: child)
73
+ else
74
+ child.call
75
+ end
76
+ end
77
+
78
+ def __hyperstack_component_select_wrappers(&block)
79
+ RescueWrapper.after_error_args = nil
80
+ __hyperstack_component_run_post_render_hooks(
81
+ __hyperstack_component_rescue_wrapper(
82
+ __hyperstack_router_wrapper(&block)
83
+ )
84
+ )
85
+ end
86
+
50
87
  def set_or_replace_state_or_prop(state_or_prop, method, &block)
51
88
  raise "No native ReactComponent associated" unless @__hyperstack_component_native
52
89
  `var state_prop_n = #{state_or_prop.shallow_to_n}`
@@ -9,7 +9,7 @@ module Hyperstack
9
9
  def instance_var_name_for(name)
10
10
  case Hyperstack.naming_convention
11
11
  when :camelize_params
12
- name.camelize
12
+ fix_suffix(name.camelize)
13
13
  when :prefix_params
14
14
  "_#{name}"
15
15
  else
@@ -17,6 +17,17 @@ module Hyperstack
17
17
  end
18
18
  end
19
19
 
20
+ def fix_suffix(name)
21
+ return unless name
22
+ if name =~ /\?$/
23
+ name[0..-2] + '_q'
24
+ elsif name =~ /\!$/
25
+ name[0..-2] + '_b'
26
+ else
27
+ name
28
+ end
29
+ end
30
+
20
31
  def param_accessor_style(style = nil)
21
32
  @param_accessor_style = style if style
22
33
  @param_accessor_style ||=
@@ -38,11 +49,14 @@ module Hyperstack
38
49
 
39
50
  def define_param(name, param_type, aka = nil)
40
51
  meth_name = aka || name
41
- var_name = aka || instance_var_name_for(name)
52
+ var_name = fix_suffix(aka) || instance_var_name_for(name)
42
53
  param_definitions[name] = lambda do |props|
43
- @component.instance_variable_set :"@#{var_name}", fetch_from_cache(name, param_type, props)
54
+ @component.instance_variable_set :"@#{var_name}", val = fetch_from_cache(name, param_type, props)
55
+ next unless param_accessor_style == :accessors
56
+ `#{@component}[#{"$#{meth_name}"}] = function() { return #{val} }`
57
+ # @component.define_singleton_method(name) { val } if param_accessor_style == :accessors
44
58
  end
45
- return if param_accessor_style == :hyperstack
59
+ return if %i[hyperstack accessors].include? param_accessor_style
46
60
  if param_type == Proc
47
61
  define_method(meth_name.to_sym) do |*args, &block|
48
62
  props[name].call(*args, &block) if props[name]
@@ -57,7 +71,10 @@ module Hyperstack
57
71
  def define_all_others(name)
58
72
  var_name = instance_var_name_for(name)
59
73
  param_definitions[name] = lambda do |props|
60
- @component.instance_variable_set :"@#{var_name}", yield(props)
74
+ @component.instance_variable_set :"@#{var_name}", val = yield(props)
75
+ next unless param_accessor_style == :accessors
76
+ `#{@component}[#{"$#{name}"}] = function() { return #{val} }`
77
+ # @component.define_singleton_method(name) { val } if param_accessor_style == :accessors
61
78
  end
62
79
  define_method(name.to_sym) do
63
80
  @_all_others_cache ||= yield(props)
@@ -1,5 +1,19 @@
1
1
  require 'action_controller'
2
2
 
3
+ module Hyperstack
4
+ module Internal
5
+ module Component
6
+ class Redirect < StandardError
7
+ attr_reader :url
8
+ def initialize(url)
9
+ @url = url
10
+ super("redirect to #{url}")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
3
17
  module ActionController
4
18
  # adds render_component helper to ActionControllers
5
19
  class Base
@@ -7,8 +21,13 @@ module ActionController
7
21
  @component_name = (args[0].is_a? Hash) || args.empty? ? params[:action].camelize : args.shift
8
22
  @render_params = args.shift || {}
9
23
  options = args[0] || {}
24
+ return if performed?
10
25
  render inline: '<%= react_component @component_name, @render_params %>',
11
26
  layout: options.key?(:layout) ? options[:layout].to_s : :default
27
+ rescue Exception => e
28
+ m = /^RuntimeError: Hyperstack::Internal::Component::Redirect (.+) status: (.+)$/.match(e.message)
29
+ raise e unless m
30
+ redirect_to m[1], status: m[2]
12
31
  end
13
32
  end
14
33
  end
@@ -153,7 +153,7 @@ module Hyperstack
153
153
  # that responds to render to act as a component we have to make sure that
154
154
  # we have a callbacks_for method. This all becomes much easier once issue
155
155
  # #270 is resolved.
156
- if type.respond_to?(:callbacks_for) && type.callbacks_for(:after_error) != []
156
+ if type.respond_to?(:callbacks?) && type.callbacks?(:after_error)
157
157
  add_after_error_hook_to_native comp
158
158
  end
159
159
  comp
@@ -261,7 +261,7 @@ module Hyperstack
261
261
  }
262
262
  }
263
263
 
264
- elsif key == 'dom'
264
+ elsif key == 'jq_ref'
265
265
  unless value.respond_to?(:call)
266
266
  raise "The ref and dom params must be given a Proc.\n"\
267
267
  "If you want to capture the dom node in an instance variable use the `set` method.\n"\
@@ -2,9 +2,23 @@ module Hyperstack
2
2
  module Internal
3
3
  module Component
4
4
  class RenderingContext
5
+ class NotQuiet < Exception; end
5
6
  class << self
6
7
  attr_accessor :waiting_on_resources
7
8
 
9
+ def raise_if_not_quiet?
10
+ @raise_if_not_quiet
11
+ end
12
+
13
+ def raise_if_not_quiet=(x)
14
+ @raise_if_not_quiet = x
15
+ end
16
+
17
+ def quiet_test(component)
18
+ return unless component.waiting_on_resources && raise_if_not_quiet? #&& component.class != RescueMetaWrapper <- WHY can't create a spec that this fails without this, but several fail with it.
19
+ raise NotQuiet.new("#{component} is waiting on resources")
20
+ end
21
+
8
22
  def render(name, *args, &block)
9
23
  was_outer_most = !@not_outer_most
10
24
  @not_outer_most = true
@@ -12,7 +26,7 @@ module Hyperstack
12
26
  @buffer ||= [] unless @buffer
13
27
  if block
14
28
  element = build do
15
- saved_waiting_on_resources = waiting_on_resources
29
+ saved_waiting_on_resources = nil #waiting_on_resources what was the purpose of this its used below to or in with the current elements waiting_for_resources
16
30
  self.waiting_on_resources = nil
17
31
  run_child_block(name.nil?, &block)
18
32
  if name
@@ -129,7 +143,7 @@ module Hyperstack
129
143
  end
130
144
 
131
145
  class Object
132
- [:span, :td, :th, :while_loading].each do |tag|
146
+ [:span, :td, :th].each do |tag|
133
147
  define_method(tag) do |*args, &block|
134
148
  args.unshift(tag)
135
149
  # legacy hyperloop allowed tags to be lower case as well so if self is a component
@@ -0,0 +1,40 @@
1
+ module Hyperstack
2
+ module Internal
3
+ module Component
4
+ class RescueMetaWrapper
5
+ include Hyperstack::Component
6
+
7
+ param :children_elements
8
+
9
+ render do
10
+ @ChildrenElements.call
11
+ end
12
+ end
13
+
14
+ class RescueWrapper
15
+ class << self
16
+ attr_accessor :after_error_args
17
+ end
18
+
19
+ include Hyperstack::Component
20
+
21
+ param :child
22
+ param :children_elements
23
+
24
+ render do
25
+ RescueMetaWrapper(children_elements: @ChildrenElements)
26
+ end
27
+
28
+ after_error do |error, info|
29
+ args = RescueWrapper.after_error_args || [error, info]
30
+ found, * = @Child.run_callback(:__hyperstack_component_rescue_hook, found, *args) { |a| a }
31
+ unless found
32
+ RescueWrapper.after_error_args = args
33
+ raise error
34
+ end
35
+ @Child.force_update!
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -30,7 +30,7 @@ module Hyperstack
30
30
  if respond_to?(:needs_update?)
31
31
  !!call_needs_update(next_props, next_state)
32
32
  else
33
- (props_changed?(next_props) || native_state_changed?(next_state))
33
+ props_changed?(next_props) || native_state_changed?(next_state)
34
34
  end
35
35
  # rubocop:enable Style/DoubleNegation
36
36
  end
@@ -0,0 +1,29 @@
1
+ module Hyperstack
2
+ module Internal
3
+ module Component
4
+ class WhileLoadingWrapper < RescueWrapper
5
+ render do
6
+ if @waiting_on_resources && !quiet?
7
+ RenderingContext.raise_if_not_quiet = false
8
+ else
9
+ @waiting_on_resources = false
10
+ @Child.instance_eval do
11
+ mutate if @__hyperstack_while_loading_waiting_on_resources
12
+ @__hyperstack_while_loading_waiting_on_resources = false
13
+ end
14
+ RenderingContext.raise_if_not_quiet = true
15
+ end
16
+ RescueMetaWrapper(children_elements: @ChildrenElements)
17
+ end
18
+
19
+ before_mount do
20
+ wrapper = self
21
+ @Child.class.rescues RenderingContext::NotQuiet do
22
+ wrapper.instance_variable_set(:@waiting_on_resources, true)
23
+ @__hyperstack_while_loading_waiting_on_resources = true
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.alpha1.2
4
+ version: 1.0.alpha1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chang
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-11-16 00:00:00.000000000 Z
15
+ date: 2019-01-17 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: hyper-state
@@ -20,56 +20,56 @@ dependencies:
20
20
  requirements:
21
21
  - - '='
22
22
  - !ruby/object:Gem::Version
23
- version: 1.0.alpha1.2
23
+ version: 1.0.alpha1.3
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - '='
29
29
  - !ruby/object:Gem::Version
30
- version: 1.0.alpha1.2
30
+ version: 1.0.alpha1.3
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: hyperstack-config
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.0.alpha1.2
37
+ version: 1.0.alpha1.3
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - '='
43
43
  - !ruby/object:Gem::Version
44
- version: 1.0.alpha1.2
44
+ version: 1.0.alpha1.3
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: libv8
47
47
  requirement: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - "~>"
50
50
  - !ruby/object:Gem::Version
51
- version: 6.3.0
51
+ version: 6.7.0
52
52
  type: :runtime
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
- version: 6.3.0
58
+ version: 6.7.0
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: mini_racer
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: 0.1.15
65
+ version: 0.2.4
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: 0.1.15
72
+ version: 0.2.4
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: opal
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -128,16 +128,22 @@ dependencies:
128
128
  name: bundler
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - "~>"
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 1.17.3
134
+ - - "<"
132
135
  - !ruby/object:Gem::Version
133
- version: 1.16.0
136
+ version: '2.1'
134
137
  type: :development
135
138
  prerelease: false
136
139
  version_requirements: !ruby/object:Gem::Requirement
137
140
  requirements:
138
- - - "~>"
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 1.17.3
144
+ - - "<"
139
145
  - !ruby/object:Gem::Version
140
- version: 1.16.0
146
+ version: '2.1'
141
147
  - !ruby/object:Gem::Dependency
142
148
  name: chromedriver-helper
143
149
  requirement: !ruby/object:Gem::Requirement
@@ -158,14 +164,14 @@ dependencies:
158
164
  requirements:
159
165
  - - '='
160
166
  - !ruby/object:Gem::Version
161
- version: 1.0.alpha1.2
167
+ version: 1.0.alpha1.3
162
168
  type: :development
163
169
  prerelease: false
164
170
  version_requirements: !ruby/object:Gem::Requirement
165
171
  requirements:
166
172
  - - '='
167
173
  - !ruby/object:Gem::Version
168
- version: 1.0.alpha1.2
174
+ version: 1.0.alpha1.3
169
175
  - !ruby/object:Gem::Dependency
170
176
  name: jquery-rails
171
177
  requirement: !ruby/object:Gem::Requirement
@@ -433,6 +439,7 @@ files:
433
439
  - lib/hyperstack/component/react_api.rb
434
440
  - lib/hyperstack/component/server.rb
435
441
  - lib/hyperstack/component/version.rb
442
+ - lib/hyperstack/component/while_loading.rb
436
443
  - lib/hyperstack/ext/component/boolean.rb
437
444
  - lib/hyperstack/ext/component/element.rb
438
445
  - lib/hyperstack/ext/component/hash.rb
@@ -454,10 +461,12 @@ files:
454
461
  - lib/hyperstack/internal/component/rails/server_rendering/hyper_asset_container.rb
455
462
  - lib/hyperstack/internal/component/react_wrapper.rb
456
463
  - lib/hyperstack/internal/component/rendering_context.rb
464
+ - lib/hyperstack/internal/component/rescue_wrapper.rb
457
465
  - lib/hyperstack/internal/component/should_component_update.rb
458
466
  - lib/hyperstack/internal/component/tags.rb
459
467
  - lib/hyperstack/internal/component/top_level_rails_component.rb
460
468
  - lib/hyperstack/internal/component/validator.rb
469
+ - lib/hyperstack/internal/component/while_loading_wrapper.rb
461
470
  - lib/react/react-source-browser.rb
462
471
  - lib/react/react-source-server.rb
463
472
  - lib/react/react-source.rb
@@ -481,8 +490,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
481
490
  - !ruby/object:Gem::Version
482
491
  version: 1.3.1
483
492
  requirements: []
484
- rubyforge_project:
485
- rubygems_version: 2.7.8
493
+ rubygems_version: 3.0.2
486
494
  signing_key:
487
495
  specification_version: 4
488
496
  summary: Opal Ruby wrapper of React.js library.