hyper-component 0.99.6 → 1.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -3
- data/Gemfile +4 -3
- data/Gemfile.lock +51 -36
- data/{misc/how-component-name-lookup-works.md → how-component-name-lookup-works.md} +1 -1
- data/hyper-component.gemspec +9 -8
- data/lib/hyper-component.rb +31 -43
- data/lib/hyperstack/component.rb +145 -0
- data/lib/hyperstack/component/auto-import.rb +44 -0
- data/lib/hyperstack/component/children.rb +40 -0
- data/lib/hyperstack/component/element.rb +129 -0
- data/lib/hyperstack/component/event.rb +78 -0
- data/lib/hyperstack/component/haml.rb +18 -0
- data/lib/hyperstack/component/isomorphic_helpers.rb +235 -0
- data/lib/hyperstack/component/jquery.rb +2 -0
- data/lib/hyperstack/component/native_library.rb +92 -0
- data/lib/hyperstack/component/react_api.rb +142 -0
- data/lib/hyperstack/component/server.rb +21 -0
- data/lib/hyperstack/component/version.rb +5 -0
- data/lib/hyperstack/ext/component/boolean.rb +14 -0
- data/lib/{react/ext/opal-jquery → hyperstack/ext/component}/element.rb +17 -12
- data/lib/{react/ext → hyperstack/ext/component}/hash.rb +0 -0
- data/lib/{react/to_key.rb → hyperstack/ext/component/number.rb} +0 -12
- data/lib/hyperstack/ext/component/object.rb +32 -0
- data/lib/{reactive-ruby → hyperstack/ext/component}/serializers.rb +0 -0
- data/lib/{react/ext → hyperstack/ext/component}/string.rb +0 -0
- data/lib/hyperstack/internal/component.rb +16 -0
- data/lib/hyperstack/internal/component/class_methods.rb +212 -0
- data/lib/hyperstack/internal/component/haml.rb +56 -0
- data/lib/hyperstack/internal/component/instance_methods.rb +92 -0
- data/lib/hyperstack/internal/component/props_wrapper.rb +125 -0
- data/lib/hyperstack/internal/component/rails.rb +11 -0
- data/lib/hyperstack/internal/component/rails/component_loader.rb +49 -0
- data/lib/hyperstack/internal/component/rails/component_mount.rb +52 -0
- data/lib/{reactive-ruby → hyperstack/internal/component}/rails/controller_helper.rb +0 -0
- data/lib/hyperstack/internal/component/rails/railtie.rb +24 -0
- data/lib/hyperstack/internal/component/rails/server_rendering/contextual_renderer.rb +52 -0
- data/lib/hyperstack/internal/component/rails/server_rendering/hyper_asset_container.rb +52 -0
- data/lib/hyperstack/internal/component/react_wrapper.rb +308 -0
- data/lib/hyperstack/internal/component/rendering_context.rb +165 -0
- data/lib/hyperstack/internal/component/should_component_update.rb +101 -0
- data/lib/hyperstack/internal/component/tags.rb +109 -0
- data/lib/hyperstack/internal/component/top_level_rails_component.rb +83 -0
- data/lib/hyperstack/internal/component/validator.rb +149 -0
- data/lib/react/react-source.rb +2 -2
- data/unmounting-objects.md +78 -0
- metadata +73 -85
- data/DOCS.md +0 -1515
- data/LICENSE +0 -19
- data/README.md +0 -49
- data/lib/hyper-component/jquery.rb +0 -2
- data/lib/rails-helpers/top_level_rails_component.rb +0 -79
- data/lib/react/api.rb +0 -272
- data/lib/react/callbacks.rb +0 -42
- data/lib/react/children.rb +0 -38
- data/lib/react/component.rb +0 -189
- data/lib/react/component/api.rb +0 -70
- data/lib/react/component/base.rb +0 -13
- data/lib/react/component/class_methods.rb +0 -175
- 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 -90
- data/lib/react/component/should_component_update.rb +0 -99
- data/lib/react/component/tags.rb +0 -116
- data/lib/react/config.rb +0 -5
- data/lib/react/element.rb +0 -167
- data/lib/react/event.rb +0 -76
- data/lib/react/native_library.rb +0 -87
- data/lib/react/object.rb +0 -15
- data/lib/react/ref_callback.rb +0 -31
- data/lib/react/rendering_context.rb +0 -149
- data/lib/react/server.rb +0 -19
- 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 -71
- data/lib/react/top_level.rb +0 -110
- data/lib/react/top_level_render.rb +0 -30
- data/lib/react/validator.rb +0 -132
- data/lib/reactive-ruby/component_loader.rb +0 -43
- data/lib/reactive-ruby/isomorphic_helpers.rb +0 -233
- data/lib/reactive-ruby/rails.rb +0 -8
- data/lib/reactive-ruby/rails/component_mount.rb +0 -48
- data/lib/reactive-ruby/rails/railtie.rb +0 -20
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +0 -46
- data/lib/reactive-ruby/server_rendering/hyper_asset_container.rb +0 -46
- data/lib/reactive-ruby/version.rb +0 -5
- data/lib/reactrb/auto-import.rb +0 -27
- data/misc/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
- data/misc/generators/reactive_ruby/test_app/templates/assets/javascripts/server_rendering.js +0 -5
- data/misc/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +0 -2
- data/misc/generators/reactive_ruby/test_app/templates/boot.rb.erb +0 -6
- data/misc/generators/reactive_ruby/test_app/templates/script/rails +0 -5
- data/misc/generators/reactive_ruby/test_app/templates/test_application.rb.erb +0 -13
- data/misc/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
- data/misc/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
- data/misc/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb +0 -0
- data/misc/generators/reactive_ruby/test_app/test_app_generator.rb +0 -121
- data/misc/hyperloop-logo-small-pink.png +0 -0
- data/misc/logo1.png +0 -0
- data/misc/logo2.png +0 -0
- data/misc/logo3.png +0 -0
- data/path_release_steps.md +0 -9
data/lib/react/event.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
class Event
|
3
|
-
include Native
|
4
|
-
alias_native :bubbles, :bubbles
|
5
|
-
alias_native :cancelable, :cancelable
|
6
|
-
alias_native :current_target, :currentTarget
|
7
|
-
alias_native :default_prevented, :defaultPrevented
|
8
|
-
alias_native :event_phase, :eventPhase
|
9
|
-
alias_native :is_trusted?, :isTrusted
|
10
|
-
alias_native :native_event, :nativeEvent
|
11
|
-
alias_native :target, :target
|
12
|
-
alias_native :timestamp, :timeStamp
|
13
|
-
alias_native :event_type, :type
|
14
|
-
alias_native :prevent_default, :preventDefault
|
15
|
-
alias_native :stop_propagation, :stopPropagation
|
16
|
-
# Clipboard
|
17
|
-
alias_native :clipboard_data, :clipboardData
|
18
|
-
# Keyboard
|
19
|
-
alias_native :alt_key, :altKey
|
20
|
-
alias_native :char_code, :charCode
|
21
|
-
alias_native :ctrl_key, :ctrlKey
|
22
|
-
alias_native :get_modifier_state, :getModifierState
|
23
|
-
alias_native :key, :key
|
24
|
-
alias_native :key_code, :keyCode
|
25
|
-
alias_native :locale, :locale
|
26
|
-
alias_native :location, :location
|
27
|
-
alias_native :meta_key, :metaKey
|
28
|
-
alias_native :repeat, :repeat
|
29
|
-
alias_native :shift_key, :shiftKey
|
30
|
-
alias_native :which, :which
|
31
|
-
# Focus
|
32
|
-
alias_native :related_target, :relatedTarget
|
33
|
-
# Mouse
|
34
|
-
# aliased above: alias_native :alt_key, :altKey
|
35
|
-
alias_native :button, :button
|
36
|
-
alias_native :buttons, :buttons
|
37
|
-
alias_native :client_x, :clientX
|
38
|
-
alias_native :client_y, :clientY
|
39
|
-
# aliased above: alias_native :ctrl_key, :ctrlKey
|
40
|
-
alias_native :get_modifier_state, :getModifierState
|
41
|
-
# aliased above: alias_native :meta_key, :metaKey
|
42
|
-
alias_native :page_x, :pageX
|
43
|
-
alias_native :page_y, :pageY
|
44
|
-
# aliased above: alias_native :related_target, :relatedTarget
|
45
|
-
alias_native :screen_x, :screen_x
|
46
|
-
alias_native :screen_y, :screen_y
|
47
|
-
# aliased above: alias_native :shift_key, :shift_key
|
48
|
-
# Touch
|
49
|
-
# aliased above: alias_native :alt_key, :altKey
|
50
|
-
alias_native :changed_touches, :changedTouches
|
51
|
-
# aliased above: alias_native :ctrl_key, :ctrlKey
|
52
|
-
# aliased above: alias_native :get_modifier_state, :getModifierState
|
53
|
-
# aliased above: alias_native :meta_key, :metaKey
|
54
|
-
# aliased above: alias_native :shift_key, :shiftKey
|
55
|
-
alias_native :target_touches, :targetTouches
|
56
|
-
alias_native :touches, :touches
|
57
|
-
# UI
|
58
|
-
alias_native :detail, :detail
|
59
|
-
alias_native :view, :view
|
60
|
-
# Wheel
|
61
|
-
alias_native :delta_mode, :deltaMode
|
62
|
-
alias_native :delta_x, :deltaX
|
63
|
-
alias_native :delta_y, :deltaY
|
64
|
-
alias_native :delta_z, :deltaZ
|
65
|
-
|
66
|
-
BUILT_IN_EVENTS = %w{onCopy onCut onPaste onKeyDown onKeyPress onKeyUp
|
67
|
-
onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick onDrag
|
68
|
-
onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop
|
69
|
-
onMouseDown onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver
|
70
|
-
onMouseUp onSelect onTouchCancel onTouchEnd onTouchMove onTouchStart onScroll onWheel}
|
71
|
-
|
72
|
-
def initialize(native_event)
|
73
|
-
@native = native_event
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/react/native_library.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
# NativeLibrary handles importing JS libraries. Importing native components is handled
|
3
|
-
# by the React::Base. It also provides several methods used by auto-import.rb
|
4
|
-
|
5
|
-
# A NativeLibrary is simply a wrapper that holds the name of the native js library.
|
6
|
-
# It responds to const_missing and method_missing by looking up objects within the js library.
|
7
|
-
# If the object is a react component it is wrapped by a reactrb component class, otherwise
|
8
|
-
# a nested NativeLibrary is returned.
|
9
|
-
|
10
|
-
# Two macros are provided: imports (for naming the native library) and renames which allows
|
11
|
-
# the members of a library to be given different names within the ruby name space.
|
12
|
-
|
13
|
-
# Public methods used by auto-import.rb are import_const_from_native and find_and_render_component
|
14
|
-
class NativeLibrary
|
15
|
-
class << self
|
16
|
-
def imports(native_name)
|
17
|
-
@native_prefix = "#{native_name}."
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
def rename(rename_list)
|
22
|
-
# rename_list is a hash in the form: native_name => ruby_name, native_name => ruby_name
|
23
|
-
rename_list.each do |js_name, ruby_name|
|
24
|
-
native_name = lookup_native_name(js_name)
|
25
|
-
if lookup_native_name(js_name)
|
26
|
-
create_component_wrapper(self, native_name, ruby_name) ||
|
27
|
-
create_library_wrapper(self, native_name, ruby_name)
|
28
|
-
else
|
29
|
-
raise "class #{name} < React::NativeLibrary could not import #{js_name}. "\
|
30
|
-
"Native value #{scope_native_name(js_name)} is undefined."
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def import_const_from_native(klass, const_name, create_library)
|
36
|
-
native_name = lookup_native_name(const_name) ||
|
37
|
-
lookup_native_name(const_name[0].downcase + const_name[1..-1])
|
38
|
-
native_name && (
|
39
|
-
create_component_wrapper(klass, native_name, const_name) || (
|
40
|
-
create_library &&
|
41
|
-
create_library_wrapper(klass, native_name, const_name)))
|
42
|
-
end
|
43
|
-
|
44
|
-
def const_missing(const_name)
|
45
|
-
import_const_from_native(self, const_name, true) || super
|
46
|
-
end
|
47
|
-
|
48
|
-
def method_missing(method, *args, &block)
|
49
|
-
component_class = const_get(method) if const_defined?(method, false)
|
50
|
-
component_class ||= import_const_from_native(self, method, false)
|
51
|
-
raise 'could not import a react component named: '\
|
52
|
-
"#{scope_native_name method}" unless component_class
|
53
|
-
React::RenderingContext.render(component_class, *args, &block)
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def lookup_native_name(js_name)
|
59
|
-
native_name = scope_native_name(js_name)
|
60
|
-
`eval(#{native_name}) !== undefined && native_name`
|
61
|
-
# rubocop:disable Lint/RescueException # that is what eval raises in Opal >= 0.10.
|
62
|
-
rescue Exception
|
63
|
-
nil
|
64
|
-
# rubocop:enable Lint/RescueException
|
65
|
-
end
|
66
|
-
|
67
|
-
def scope_native_name(js_name)
|
68
|
-
"#{@native_prefix}#{js_name}"
|
69
|
-
end
|
70
|
-
|
71
|
-
def create_component_wrapper(klass, native_name, ruby_name)
|
72
|
-
if React::API.native_react_component?(native_name)
|
73
|
-
new_klass = klass.const_set ruby_name, Class.new
|
74
|
-
new_klass.class_eval do
|
75
|
-
include Hyperloop::Component::Mixin
|
76
|
-
imports native_name
|
77
|
-
end
|
78
|
-
new_klass
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def create_library_wrapper(klass, native_name, ruby_name)
|
83
|
-
klass.const_set ruby_name, Class.new(React::NativeLibrary).imports(native_name)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/lib/react/object.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# Lazy load HTML tag constants in the form DIV or A
|
2
|
-
# This is needed to allow for a HAML expression like this DIV.my_class
|
3
|
-
class Object
|
4
|
-
class << self
|
5
|
-
alias _reactrb_tag_original_const_missing const_missing
|
6
|
-
|
7
|
-
def const_missing(const_name)
|
8
|
-
# Opal uses const_missing to initially define things,
|
9
|
-
# so we always call the original, and respond to the exception
|
10
|
-
_reactrb_tag_original_const_missing(const_name)
|
11
|
-
rescue StandardError => e
|
12
|
-
React::Component::Tags.html_tag_class_for(const_name) || raise(e)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/react/ref_callback.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'react/native_library'
|
2
|
-
|
3
|
-
module React
|
4
|
-
module RefsCallbackExtension
|
5
|
-
end
|
6
|
-
|
7
|
-
class API
|
8
|
-
class << self
|
9
|
-
alias :orig_convert_props :convert_props
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.convert_props(properties)
|
13
|
-
props = self.orig_convert_props(properties)
|
14
|
-
props.map do |key, value|
|
15
|
-
if key == "ref" && value.is_a?(Proc)
|
16
|
-
new_proc = Proc.new do |native_inst|
|
17
|
-
if `#{native_inst} !== null && #{native_inst}.__opalInstance !== undefined && #{native_inst}.__opalInstance !== null`
|
18
|
-
value.call(`#{native_inst}.__opalInstance`)
|
19
|
-
elsif `#{native_inst} !== null && ReactDOM.findDOMNode !== undefined && #{native_inst}.nodeType === undefined`
|
20
|
-
value.call(`ReactDOM.findDOMNode(#{native_inst})`) # react >= v0.15.`)
|
21
|
-
else
|
22
|
-
value.call(native_inst)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
props[key] = new_proc
|
26
|
-
end
|
27
|
-
end
|
28
|
-
props
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
class RenderingContext
|
3
|
-
class << self
|
4
|
-
attr_accessor :waiting_on_resources
|
5
|
-
|
6
|
-
def render(name, *args, &block)
|
7
|
-
was_outer_most = !@not_outer_most
|
8
|
-
@not_outer_most = true
|
9
|
-
remove_nodes_from_args(args)
|
10
|
-
@buffer ||= [] unless @buffer
|
11
|
-
if block
|
12
|
-
element = build do
|
13
|
-
saved_waiting_on_resources = waiting_on_resources
|
14
|
-
self.waiting_on_resources = nil
|
15
|
-
run_child_block(name.nil?, &block)
|
16
|
-
if name
|
17
|
-
buffer = @buffer.dup
|
18
|
-
React::API.create_element(name, *args) { buffer }.tap do |element|
|
19
|
-
element.waiting_on_resources = saved_waiting_on_resources || !!buffer.detect { |e| e.waiting_on_resources if e.respond_to?(:waiting_on_resources) }
|
20
|
-
element.waiting_on_resources ||= waiting_on_resources if buffer.last.is_a?(String)
|
21
|
-
end
|
22
|
-
elsif @buffer.last.is_a? React::Element
|
23
|
-
@buffer.last.tap { |element| element.waiting_on_resources ||= saved_waiting_on_resources }
|
24
|
-
else
|
25
|
-
buffer_s = @buffer.last.to_s
|
26
|
-
React::RenderingContext.render(:span) { buffer_s }.tap { |element| element.waiting_on_resources = saved_waiting_on_resources }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
elsif name.is_a? React::Element
|
30
|
-
element = name
|
31
|
-
else
|
32
|
-
element = React::API.create_element(name, *args)
|
33
|
-
element.waiting_on_resources = waiting_on_resources
|
34
|
-
end
|
35
|
-
@buffer << element
|
36
|
-
self.waiting_on_resources = nil
|
37
|
-
element
|
38
|
-
ensure
|
39
|
-
@not_outer_most = @buffer = nil if was_outer_most
|
40
|
-
end
|
41
|
-
|
42
|
-
def build
|
43
|
-
current = @buffer
|
44
|
-
@buffer = []
|
45
|
-
return_val = yield @buffer
|
46
|
-
@buffer = current
|
47
|
-
return_val
|
48
|
-
end
|
49
|
-
|
50
|
-
def delete(element)
|
51
|
-
@buffer.delete(element)
|
52
|
-
element
|
53
|
-
end
|
54
|
-
alias as_node delete
|
55
|
-
|
56
|
-
def rendered?(element)
|
57
|
-
@buffer.include? element
|
58
|
-
end
|
59
|
-
|
60
|
-
def replace(e1, e2)
|
61
|
-
@buffer[@buffer.index(e1)] = e2
|
62
|
-
end
|
63
|
-
|
64
|
-
def remove_nodes_from_args(args)
|
65
|
-
args[0].each do |key, value|
|
66
|
-
begin
|
67
|
-
value.delete if value.is_a?(Element) # deletes Element from buffer
|
68
|
-
rescue Exception
|
69
|
-
end
|
70
|
-
end if args[0] && args[0].is_a?(Hash)
|
71
|
-
end
|
72
|
-
|
73
|
-
# run_child_block gathers the element(s) generated by a child block.
|
74
|
-
# for example when rendering this div: div { "hello".span; "goodby".span }
|
75
|
-
# two child Elements will be generated.
|
76
|
-
#
|
77
|
-
# the final value of the block should either be
|
78
|
-
# 1 an object that responds to :acts_as_string?
|
79
|
-
# 2 a string,
|
80
|
-
# 3 an element that is NOT yet pushed on the rendering buffer
|
81
|
-
# 4 or the last element pushed on the buffer
|
82
|
-
#
|
83
|
-
# in case 1 we render a span
|
84
|
-
# in case 2 we automatically push the string onto the buffer
|
85
|
-
# in case 3 we also push the Element onto the buffer IF the buffer is empty
|
86
|
-
# case 4 requires no special processing
|
87
|
-
#
|
88
|
-
# Once we have taken care of these special cases we do a check IF we are in an
|
89
|
-
# outer rendering scope. In this case react only allows us to generate 1 Element
|
90
|
-
# so we insure that is the case, and also check to make sure that element in the buffer
|
91
|
-
# is the element returned
|
92
|
-
|
93
|
-
def run_child_block(is_outer_scope)
|
94
|
-
result = yield
|
95
|
-
if result.respond_to?(:acts_as_string?) && result.acts_as_string?
|
96
|
-
# hyper-mesh DummyValues respond to acts_as_string, and must
|
97
|
-
# be converted to spans INSIDE the parent, otherwise the waiting_on_resources
|
98
|
-
# flag will get set in the wrong context
|
99
|
-
React::RenderingContext.render(:span) { result.to_s }
|
100
|
-
elsif result.is_a?(String) || (result.is_a?(React::Element) && @buffer.empty?)
|
101
|
-
@buffer << result
|
102
|
-
end
|
103
|
-
raise_render_error(result) if is_outer_scope && @buffer != [result]
|
104
|
-
end
|
105
|
-
|
106
|
-
# heurestically raise a meaningful error based on the situation
|
107
|
-
|
108
|
-
def raise_render_error(result)
|
109
|
-
improper_render 'A different element was returned than was generated within the DSL.',
|
110
|
-
'Possibly improper use of Element#delete.' if @buffer.count == 1
|
111
|
-
improper_render "Instead #{@buffer.count} elements were generated.",
|
112
|
-
'Do you want to wrap your elements in a div?' if @buffer.count > 1
|
113
|
-
improper_render "Instead the component #{result} was returned.",
|
114
|
-
"Did you mean #{result}()?" if result.try :reactrb_component?
|
115
|
-
improper_render "Instead the #{result.class} #{result} was returned.",
|
116
|
-
'You may need to convert this to a string.'
|
117
|
-
end
|
118
|
-
|
119
|
-
def improper_render(message, solution)
|
120
|
-
raise "a component's render method must generate and return exactly 1 element or a string.\n"\
|
121
|
-
" #{message} #{solution}"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
class Object
|
128
|
-
[:span, :td, :th, :while_loading].each do |tag|
|
129
|
-
define_method(tag) do |*args, &block|
|
130
|
-
args.unshift(tag)
|
131
|
-
return send(*args, &block) if is_a? React::Component
|
132
|
-
React::RenderingContext.render(*args) { to_s }
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def para(*args, &block)
|
137
|
-
args.unshift(:p)
|
138
|
-
return send(*args, &block) if is_a? React::Component
|
139
|
-
React::RenderingContext.render(*args) { to_s }
|
140
|
-
end
|
141
|
-
|
142
|
-
def br
|
143
|
-
return send(:br) if is_a? React::Component
|
144
|
-
React::RenderingContext.render(:span) do
|
145
|
-
React::RenderingContext.render(to_s)
|
146
|
-
React::RenderingContext.render(:br)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
data/lib/react/server.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Server
|
3
|
-
def self.render_to_string(element)
|
4
|
-
if !(`typeof ReactDOMServer === 'undefined'`)
|
5
|
-
React::RenderingContext.build { `ReactDOMServer.renderToString(#{element.to_n})` } # v0.15+
|
6
|
-
else
|
7
|
-
raise "renderToString is not defined. In React >= v15 you must import it with ReactDOMServer"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.render_to_static_markup(element)
|
12
|
-
if !(`typeof ReactDOMServer === 'undefined'`)
|
13
|
-
React::RenderingContext.build { `ReactDOMServer.renderToStaticMarkup(#{element.to_n})` } # v0.15+
|
14
|
-
else
|
15
|
-
raise "renderToStaticMarkup is not defined. In React >= v15 you must import it with ReactDOMServer"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/react/state_wrapper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module HyperStore
|
2
|
-
class StateWrapper < BaseStoreClass # < BasicObject
|
3
|
-
|
4
|
-
def [](state)
|
5
|
-
`#{__from__.instance_variable_get('@native')}.state[#{state}] || #{nil}`
|
6
|
-
end
|
7
|
-
|
8
|
-
def []=(state, new_value)
|
9
|
-
`#{__from__.instance_variable_get('@native')}.state[#{state}] = new_value`
|
10
|
-
end
|
11
|
-
|
12
|
-
alias pre_component_method_missing method_missing
|
13
|
-
|
14
|
-
def method_missing(method, *args)
|
15
|
-
if method.end_with?('!') && __from__.respond_to?(:deprecation_warning)
|
16
|
-
__from__.deprecation_warning("The mutator 'state.#{method}' has been deprecated. Use 'mutate.#{method.sub(/\!$/,'')}' instead.")
|
17
|
-
__from__.mutate.__send__(method.chop, *args)
|
18
|
-
else
|
19
|
-
pre_component_method_missing(method, *args)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/react/test.rb
DELETED
data/lib/react/test/dsl.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'react/test'
|
2
|
-
|
3
|
-
module React
|
4
|
-
module Test
|
5
|
-
module DSL
|
6
|
-
def component
|
7
|
-
React::Test.current_session
|
8
|
-
end
|
9
|
-
|
10
|
-
Session::DSL_METHODS.each do |method|
|
11
|
-
define_method method do |*args, &block|
|
12
|
-
component.public_send(method, *args, &block)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Test
|
3
|
-
module Matchers
|
4
|
-
class RenderHTMLMatcher
|
5
|
-
def initialize(expected)
|
6
|
-
@expected = expected
|
7
|
-
@params = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_params(params)
|
11
|
-
@params = params
|
12
|
-
self
|
13
|
-
end
|
14
|
-
|
15
|
-
def matches?(component)
|
16
|
-
@component = component
|
17
|
-
@actual = render_to_html
|
18
|
-
@expected == @actual
|
19
|
-
end
|
20
|
-
|
21
|
-
def failure_message
|
22
|
-
failure_string
|
23
|
-
end
|
24
|
-
|
25
|
-
def failure_message_when_negated
|
26
|
-
failure_string(:negative)
|
27
|
-
end
|
28
|
-
|
29
|
-
alias negative_failure_message failure_message_when_negated
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def render_to_html
|
34
|
-
element = React.create_element(@component, @params)
|
35
|
-
React::Server.render_to_static_markup(element)
|
36
|
-
end
|
37
|
-
|
38
|
-
def failure_string(negative = false)
|
39
|
-
str = "expected '#{@component.name}' with params '#{@params}' to "
|
40
|
-
str = str + "not " if negative
|
41
|
-
str = str + "render '#{@expected}', but '#{@actual}' was rendered."
|
42
|
-
str
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def render_static_html(*args)
|
47
|
-
RenderHTMLMatcher.new(*args)
|
48
|
-
end
|
49
|
-
|
50
|
-
def render(*args)
|
51
|
-
%x{ console.error("Warning: `render` matcher is deprecated in favor of `render_static_html`."); }
|
52
|
-
RenderHTMLMatcher.new(*args)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|