hyper-component 1.0.alpha1.4 → 1.0.alpha1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hyper-component.rb +4 -0
- data/lib/hyperstack/component/element.rb +15 -5
- data/lib/hyperstack/component/free_render.rb +21 -0
- data/lib/hyperstack/component/version.rb +1 -1
- data/lib/hyperstack/ext/component/array.rb +20 -0
- data/lib/hyperstack/ext/component/element.rb +5 -7
- data/lib/hyperstack/ext/component/enumerable.rb +18 -0
- data/lib/hyperstack/ext/component/kernel.rb +7 -0
- data/lib/hyperstack/internal/component/class_methods.rb +3 -2
- data/lib/hyperstack/internal/component/props_wrapper.rb +13 -11
- data/lib/hyperstack/internal/component/rails/component_mount.rb +9 -0
- data/lib/hyperstack/internal/component/rails/controller_helper.rb +1 -1
- data/lib/hyperstack/internal/component/rails/railtie.rb +3 -2
- data/lib/hyperstack/internal/component/react_wrapper.rb +1 -0
- data/lib/hyperstack/internal/component/tags.rb +3 -3
- metadata +13 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eb3f7c53a31ed9f6708f9fd1251f3ed52f7d54e5894145abaaf4ac4e5ac7fce
|
4
|
+
data.tar.gz: b95ea7df69882114a1a55f772911ba2b609221bde04df9e629e1278c0e71ea73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7022103f15e46d7251addacac7ca755bb2cc2e7d52ae9ec8ebcd9fbb24ada6db90e77d3d689ad20a058a60e84192f00ea88f5d99065c2b86420187f2a0a2057
|
7
|
+
data.tar.gz: 44d0acecd8dc27123a35d0db8fa32f9cbdbe6715c523661a618114ad157891dfec8ebc226b6eff70e3a2a562271e3144d477e16f9110a8a274058edd1fb188cf
|
data/lib/hyper-component.rb
CHANGED
@@ -22,12 +22,16 @@ if RUBY_ENGINE == 'opal'
|
|
22
22
|
require 'hyperstack/component/event'
|
23
23
|
require 'hyperstack/internal/component/rendering_context'
|
24
24
|
require 'hyperstack/ext/component/object'
|
25
|
+
require 'hyperstack/ext/component/kernel'
|
25
26
|
require 'hyperstack/ext/component/number'
|
26
27
|
require 'hyperstack/ext/component/boolean'
|
28
|
+
require 'hyperstack/ext/component/array'
|
29
|
+
require 'hyperstack/ext/component/enumerable'
|
27
30
|
require 'hyperstack/component/isomorphic_helpers'
|
28
31
|
require 'hyperstack/component/react_api'
|
29
32
|
require 'hyperstack/internal/component/top_level_rails_component'
|
30
33
|
require 'hyperstack/component/while_loading'
|
34
|
+
require 'hyperstack/component/free_render'
|
31
35
|
require 'hyperstack/internal/component/rescue_wrapper'
|
32
36
|
require 'hyperstack/internal/component/while_loading_wrapper'
|
33
37
|
|
@@ -39,18 +39,25 @@ module Hyperstack
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def ref
|
42
|
-
@ref
|
42
|
+
return @ref if @ref
|
43
|
+
raise("The instance of #{self.type} has not been mounted yet") if properties[:ref]
|
44
|
+
raise("Attempt to get a ref on #{self.type} which is a static component.")
|
43
45
|
end
|
44
46
|
|
45
47
|
def dom_node
|
46
|
-
|
48
|
+
`typeof #{ref}.$dom_node == 'function'` ? ref.dom_node : ref
|
47
49
|
end
|
48
50
|
|
49
|
-
# Attach event handlers.
|
51
|
+
# Attach event handlers. skip false, nil and blank event names
|
50
52
|
|
51
53
|
def on(*event_names, &block)
|
52
|
-
|
53
|
-
|
54
|
+
any_found = false
|
55
|
+
event_names.each do |event_name|
|
56
|
+
next unless event_name && event_name.strip != ''
|
57
|
+
merge_event_prop!(event_name, &block)
|
58
|
+
any_found = true
|
59
|
+
end
|
60
|
+
@native = `React.cloneElement(#{@native}, #{@properties.shallow_to_n})` if any_found
|
54
61
|
self
|
55
62
|
end
|
56
63
|
|
@@ -114,6 +121,9 @@ module Hyperstack
|
|
114
121
|
prop_name => %x{
|
115
122
|
function(){
|
116
123
|
var react_event = arguments[0];
|
124
|
+
if (arguments.length == 0 || !react_event.nativeEvent) {
|
125
|
+
return #{yield(*Array(`arguments`))}
|
126
|
+
}
|
117
127
|
var all_args;
|
118
128
|
var other_args;
|
119
129
|
if (arguments.length > 1) {
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Hyperstack
|
2
|
+
module Component
|
3
|
+
module FreeRender
|
4
|
+
def self.included(base)
|
5
|
+
base.instance_eval do
|
6
|
+
alias :hyperstack_component_original_meth_missing method_missing
|
7
|
+
def method_missing(name, *args, &block)
|
8
|
+
if const_defined?(name) &&
|
9
|
+
(klass = const_get(name)) &&
|
10
|
+
((klass.is_a?(Class) && klass.method_defined?(:render)) ||
|
11
|
+
Hyperstack::Internal::Component::Tags::HTML_TAGS.include?(klass))
|
12
|
+
render(klass, *args, &block)
|
13
|
+
else
|
14
|
+
hyperstack_component_original_meth_missing(name, *args, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# from Rails 6.0 activesupport. Remove once defined by Opal activesupport
|
2
|
+
class Array
|
3
|
+
# Removes and returns the elements for which the block returns a true value.
|
4
|
+
# If no block is given, an Enumerator is returned instead.
|
5
|
+
#
|
6
|
+
# numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
7
|
+
# odd_numbers = numbers.extract! { |number| number.odd? } # => [1, 3, 5, 7, 9]
|
8
|
+
# numbers # => [0, 2, 4, 6, 8]
|
9
|
+
def extract!
|
10
|
+
return to_enum(:extract!) { size } unless block_given?
|
11
|
+
|
12
|
+
extracted_elements = []
|
13
|
+
|
14
|
+
reject! do |element|
|
15
|
+
extracted_elements << element if yield(element)
|
16
|
+
end
|
17
|
+
|
18
|
+
extracted_elements
|
19
|
+
end
|
20
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
Element.instance_eval do
|
2
2
|
def self.find(selector)
|
3
|
-
selector
|
4
|
-
selector.dom_node
|
5
|
-
|
6
|
-
|
7
|
-
end if `#{selector}.$dom_node !== undefined`
|
8
|
-
`$(#{selector})`
|
3
|
+
if `typeof #{selector}['$respond_to?'] == 'function'` && selector.respond_to?(:dom_node)
|
4
|
+
selector = selector.dom_node
|
5
|
+
end
|
6
|
+
`jQuery(#{selector})`
|
9
7
|
end
|
10
8
|
|
11
9
|
def self.[](selector)
|
@@ -37,7 +35,7 @@ Element.instance_eval do
|
|
37
35
|
# see react-rails documentation for more details
|
38
36
|
|
39
37
|
%x{
|
40
|
-
|
38
|
+
jQuery.fn.mount_components = function() {
|
41
39
|
this.each(function(e) { ReactRailsUJS.mountComponents(e[0]) })
|
42
40
|
return this;
|
43
41
|
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# from Rails 6.0 activesupport. Remove once defined by Opal activesupport
|
2
|
+
module Enumerable
|
3
|
+
INDEX_WITH_DEFAULT = Object.new
|
4
|
+
private_constant :INDEX_WITH_DEFAULT
|
5
|
+
def index_with(default = INDEX_WITH_DEFAULT)
|
6
|
+
if block_given?
|
7
|
+
result = {}
|
8
|
+
each { |elem| result[elem] = yield(elem) }
|
9
|
+
result
|
10
|
+
elsif default != INDEX_WITH_DEFAULT
|
11
|
+
result = {}
|
12
|
+
each { |elem| result[elem] = default }
|
13
|
+
result
|
14
|
+
else
|
15
|
+
to_enum(:index_with) { size if respond_to?(:size) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -271,7 +271,8 @@ module Hyperstack
|
|
271
271
|
ReactWrapper.import_native_component(
|
272
272
|
self, ReactWrapper.eval_native_react_component(component_name)
|
273
273
|
)
|
274
|
-
|
274
|
+
render {}
|
275
|
+
#define_method(:render) {} # define a dummy render method - will never be called...
|
275
276
|
rescue Exception => e # rubocop:disable Lint/RescueException : we need to catch everything!
|
276
277
|
raise "#{self} cannot import '#{component_name}': #{e.message}."
|
277
278
|
# rubocop:enable Lint/RescueException
|
@@ -291,7 +292,7 @@ module Hyperstack
|
|
291
292
|
end
|
292
293
|
|
293
294
|
def to_n
|
294
|
-
ReactWrapper.
|
295
|
+
Hyperstack::Internal::Component::ReactWrapper.create_native_react_class(self)
|
295
296
|
end
|
296
297
|
end
|
297
298
|
end
|
@@ -48,21 +48,23 @@ module Hyperstack
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def define_param(name, param_type, aka = nil)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
if param_accessor_style != :legacy || aka
|
52
|
+
meth_name = aka || name
|
53
|
+
var_name = fix_suffix(aka) || instance_var_name_for(name)
|
54
|
+
param_definitions[name] = lambda do |props|
|
55
|
+
@component.instance_variable_set :"@#{var_name}", val = fetch_from_cache(name, param_type, props)
|
56
|
+
next unless param_accessor_style == :accessors
|
57
|
+
`#{@component}[#{"$#{meth_name}"}] = function() { return #{val} }`
|
58
|
+
# @component.define_singleton_method(name) { val } if param_accessor_style == :accessors
|
59
|
+
end
|
60
|
+
return if %i[hyperstack accessors].include? param_accessor_style
|
58
61
|
end
|
59
|
-
return if %i[hyperstack accessors].include? param_accessor_style
|
60
62
|
if param_type == Proc
|
61
|
-
define_method(
|
63
|
+
define_method(name.to_sym) do |*args, &block|
|
62
64
|
props[name].call(*args, &block) if props[name]
|
63
65
|
end
|
64
66
|
else
|
65
|
-
define_method(
|
67
|
+
define_method(name.to_sym) do
|
66
68
|
fetch_from_cache(name, param_type, props)
|
67
69
|
end
|
68
70
|
end
|
@@ -88,7 +90,7 @@ module Hyperstack
|
|
88
90
|
|
89
91
|
def initialize(component, incoming = nil)
|
90
92
|
@component = component
|
91
|
-
return if param_accessor_style == :legacy
|
93
|
+
#return if param_accessor_style == :legacy
|
92
94
|
self.class.param_definitions.each_value do |initializer|
|
93
95
|
instance_exec(incoming || props, &initializer)
|
94
96
|
end
|
@@ -22,7 +22,7 @@ module ActionController
|
|
22
22
|
@render_params = args.shift || {}
|
23
23
|
options = args[0] || {}
|
24
24
|
return if performed?
|
25
|
-
render inline: '<%=
|
25
|
+
render inline: '<%= mount_component @component_name, @render_params %>',
|
26
26
|
layout: options.key?(:layout) ? options[:layout].to_s : :default
|
27
27
|
rescue Exception => e
|
28
28
|
m = /^RuntimeError: Hyperstack::Internal::Component::Redirect (.+) status: (.+)$/.match(e.message)
|
@@ -12,8 +12,9 @@ module Hyperstack
|
|
12
12
|
end
|
13
13
|
config.after_initialize do
|
14
14
|
class ::HyperstackController < ::ApplicationController
|
15
|
-
def action_missing(
|
16
|
-
|
15
|
+
def action_missing(*)
|
16
|
+
parts = params[:action].split('__')
|
17
|
+
render_component (parts[0..-2]+[parts.last.camelize]).join('::')
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -30,6 +30,7 @@ module Hyperstack
|
|
30
30
|
def self.eval_native_react_component(name)
|
31
31
|
component = `eval(name)`
|
32
32
|
raise "#{name} is not defined" if `#{component} === undefined`
|
33
|
+
component = `component.default` if `component.__esModule`
|
33
34
|
is_component_class = `#{component}.prototype !== undefined` &&
|
34
35
|
(`!!#{component}.prototype.isReactComponent` ||
|
35
36
|
`!!#{component}.prototype.render`)
|
@@ -85,11 +85,11 @@ module Hyperstack
|
|
85
85
|
|
86
86
|
def lookup_const(name)
|
87
87
|
return nil unless name =~ /^[A-Z]/
|
88
|
-
scopes = self.class.name.to_s.split('::').inject([
|
88
|
+
scopes = self.class.name.to_s.split('::').inject([Object]) do |nesting, next_const|
|
89
89
|
nesting + [nesting.last.const_get(next_const)]
|
90
90
|
end.reverse
|
91
|
-
scope = scopes.detect { |s| s.const_defined?(name) }
|
92
|
-
scope.const_get(name) if scope
|
91
|
+
scope = scopes.detect { |s| s.const_defined?(name, false) }
|
92
|
+
scope.const_get(name, false) if scope
|
93
93
|
end
|
94
94
|
end
|
95
95
|
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.
|
4
|
+
version: 1.0.alpha1.5
|
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: 2019-
|
15
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: hyper-state
|
@@ -20,28 +20,28 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - '='
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.0.alpha1.
|
23
|
+
version: 1.0.alpha1.5
|
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.
|
30
|
+
version: 1.0.alpha1.5
|
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.
|
37
|
+
version: 1.0.alpha1.5
|
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.
|
44
|
+
version: 1.0.alpha1.5
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: libv8
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,14 +164,14 @@ dependencies:
|
|
164
164
|
requirements:
|
165
165
|
- - '='
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version: 1.0.alpha1.
|
167
|
+
version: 1.0.alpha1.5
|
168
168
|
type: :development
|
169
169
|
prerelease: false
|
170
170
|
version_requirements: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
172
|
- - '='
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: 1.0.alpha1.
|
174
|
+
version: 1.0.alpha1.5
|
175
175
|
- !ruby/object:Gem::Dependency
|
176
176
|
name: jquery-rails
|
177
177
|
requirement: !ruby/object:Gem::Requirement
|
@@ -431,6 +431,7 @@ files:
|
|
431
431
|
- lib/hyperstack/component/children.rb
|
432
432
|
- lib/hyperstack/component/element.rb
|
433
433
|
- lib/hyperstack/component/event.rb
|
434
|
+
- lib/hyperstack/component/free_render.rb
|
434
435
|
- lib/hyperstack/component/haml.rb
|
435
436
|
- lib/hyperstack/component/isomorphic_helpers.rb
|
436
437
|
- lib/hyperstack/component/jquery.rb
|
@@ -439,9 +440,12 @@ files:
|
|
439
440
|
- lib/hyperstack/component/server.rb
|
440
441
|
- lib/hyperstack/component/version.rb
|
441
442
|
- lib/hyperstack/component/while_loading.rb
|
443
|
+
- lib/hyperstack/ext/component/array.rb
|
442
444
|
- lib/hyperstack/ext/component/boolean.rb
|
443
445
|
- lib/hyperstack/ext/component/element.rb
|
446
|
+
- lib/hyperstack/ext/component/enumerable.rb
|
444
447
|
- lib/hyperstack/ext/component/hash.rb
|
448
|
+
- lib/hyperstack/ext/component/kernel.rb
|
445
449
|
- lib/hyperstack/ext/component/number.rb
|
446
450
|
- lib/hyperstack/ext/component/object.rb
|
447
451
|
- lib/hyperstack/ext/component/serializers.rb
|
@@ -489,7 +493,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
489
493
|
- !ruby/object:Gem::Version
|
490
494
|
version: 1.3.1
|
491
495
|
requirements: []
|
492
|
-
rubygems_version: 3.0.
|
496
|
+
rubygems_version: 3.0.4
|
493
497
|
signing_key:
|
494
498
|
specification_version: 4
|
495
499
|
summary: Opal Ruby wrapper of React.js library.
|