Skip to content

Commit 23b200d

Browse files
committed
moved class_methods props_wrapper and should_component_update
1 parent 074e69e commit 23b200d

File tree

10 files changed

+22
-83
lines changed

10 files changed

+22
-83
lines changed

ruby/hyper-component/lib/hyper-component.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
require 'react/api'
1414
require 'react/component'
1515
#require 'react/component/dsl_instance_methods'
16-
require 'react/component/should_component_update'
16+
require 'hyperstack/internal/component/should_component_update'
1717
require 'hyperstack/internal/component/tags'
18-
require 'react/component/base'
1918
require 'react/event'
2019
require 'react/rendering_context'
2120
#require 'react/state'

ruby/hyper-component/lib/react/component/class_methods.rb renamed to ruby/hyper-component/lib/hyperstack/internal/component/class_methods.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Hyperstack
2-
module Component
3-
module Internal
2+
module Internal
3+
module Component
44
# class level methods (macros) for components
55
module ClassMethods
66

@@ -24,9 +24,9 @@ def append_backtrace(message_array, backtrace)
2424

2525
def render(container = nil, params = {}, &block)
2626
if container
27-
container = container.type if container.is_a? Element
27+
container = container.type if container.is_a? Hyperstack::Component::Element
2828
define_method :render do
29-
RenderingContext.render(container, params) { instance_eval(&block) if block }
29+
Hyperstack::Component::Internal::RenderingContext.render(container, params) { instance_eval(&block) if block }
3030
end
3131
else
3232
define_method(:render) { instance_eval(&block) }
@@ -46,13 +46,13 @@ def method_missing(name, *args, &children)
4646
# makes sure to autoimport the component. This is not needed here, as
4747
# we already have the class.
4848

49-
RenderingContext.render(
50-
self, class: Element.haml_class_name(name), &children
49+
Hyperstack::Component::Internal::RenderingContext.render(
50+
self, class: Hyperstack::Component::Element.haml_class_name(name), &children
5151
)
5252
end
5353

5454
def validator
55-
@validator ||= Validator.new(props_wrapper)
55+
@validator ||= Hyperstack::Component::Internal::Validator.new(props_wrapper)
5656
end
5757

5858
def prop_types
@@ -149,13 +149,13 @@ def export_component(opts = {})
149149
first_name = export_name.first
150150
Native(`Opal.global`)[first_name] = add_item_to_tree(
151151
Native(`Opal.global`)[first_name],
152-
[ReactWrapper.create_native_react_class(self)] + export_name[1..-1].reverse
152+
[Hyperstack::Component::Internal::ReactWrapper.create_native_react_class(self)] + export_name[1..-1].reverse
153153
).to_n
154154
end
155155

156156
def imports(component_name)
157-
ReactWrapper.import_native_component(
158-
self, ReactWrapper.eval_native_react_component(component_name)
157+
Hyperstack::Component::Internal::ReactWrapper.import_native_component(
158+
self, Hyperstack::Component::Internal::ReactWrapper.eval_native_react_component(component_name)
159159
)
160160
define_method(:render) {} # define a dummy render method - will never be called...
161161
rescue Exception => e # rubocop:disable Lint/RescueException : we need to catch everything!
@@ -177,7 +177,7 @@ def add_item_to_tree(current_tree, new_item)
177177
end
178178

179179
def to_n
180-
ReactWrapper.class_eval('@@component_classes')[self]
180+
Hyperstack::Component::Internal::ReactWrapper.class_eval('@@component_classes')[self]
181181
end
182182
end
183183
end

ruby/hyper-component/lib/react/component/props_wrapper.rb renamed to ruby/hyper-component/lib/hyperstack/internal/component/props_wrapper.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
module Hyperstack
2-
module Component
3-
module Internal
2+
module Internal
3+
module Component
44

55
class PropsWrapper
66
attr_reader :component
77

88
def self.define_param(name, param_type)
9-
if false && param_type == Store::Observable
10-
define_method("#{name}") do
11-
value_for(name)
12-
end
13-
define_method("#{name}!") do |*args|
14-
current_value = value_for(name)
15-
if args.count > 0
16-
props[name].call args[0]
17-
current_value
18-
else
19-
# rescue in case we in middle of render... What happens during a
20-
# render that causes exception?
21-
# Where does `dont_update_state` come from?
22-
props[name].call current_value unless @dont_update_state rescue nil
23-
props[name]
24-
end
25-
end
26-
elsif param_type == Proc
9+
if param_type == Proc
2710
define_method("#{name}") do |*args, &block|
2811
props[name].call(*args, &block) if props[name]
2912
end

ruby/hyper-component/lib/react/component/should_component_update.rb renamed to ruby/hyper-component/lib/hyperstack/internal/component/should_component_update.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Hyperstack
2-
module Component
3-
module Internal
2+
module Internal
3+
module Component
44
#
55
# React assumes all components should update, unless a component explicitly overrides
66
# the shouldComponentUpdate method. Reactrb does an explicit check doing a shallow

ruby/hyper-component/lib/react/component.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
require 'react/rendering_context'
66
require 'react/state_wrapper'
77
require 'hyperstack/internal/component/instance_methods'
8-
require 'react/component/class_methods'
9-
require 'react/component/props_wrapper'
8+
require 'hyperstack/internal/component/class_methods'
9+
require 'hyperstack/internal/component/props_wrapper'
1010
module Hyperstack
1111
module Component
1212

@@ -34,7 +34,7 @@ def self.included(base)
3434
base.include(Hyperstack::Internal::Component::Callbacks)
3535
base.include(Hyperstack::Internal::Component::Tags)
3636
#base.include(React::Component::DslInstanceMethods)
37-
base.include(Internal::ShouldComponentUpdate)
37+
base.include(Hyperstack::Internal::Component::ShouldComponentUpdate)
3838
base.class_eval do
3939
class_attribute :initial_state
4040
define_callback :before_mount
@@ -45,7 +45,7 @@ def self.included(base)
4545
define_callback :before_unmount
4646
define_callback(:after_error) { Internal::ReactWrapper.add_after_error_hook(base) }
4747
end
48-
base.extend(Internal::ClassMethods)
48+
base.extend(Hyperstack::Internal::Component::ClassMethods)
4949
end
5050

5151
def self.deprecation_warning(message)

ruby/hyper-component/lib/react/component/base.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

ruby/hyper-component/lib/react/component/not_used_dsl_instance_methods.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

ruby/hyper-component/lib/react/component/not_used_params.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

ruby/hyper-component/lib/react/top_level.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require "native"
22
require 'active_support/core_ext/object/try'
33
require 'hyperstack/internal/component/tags'
4-
require 'react/component/base'
54

65
module Hyperstack
76
module Component

ruby/hyper-component/lib/react/validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Validator
66
attr_reader :props_wrapper
77
private :errors, :props_wrapper
88

9-
def initialize(props_wrapper = Class.new(Internal::PropsWrapper))
9+
def initialize(props_wrapper = Class.new(Hyperstack::Internal::Component::PropsWrapper))
1010
@props_wrapper = props_wrapper
1111
end
1212

0 commit comments

Comments
 (0)