Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit ea6271d

Browse files
committed
Revert "wip"
This reverts commit baf71b4.
1 parent 95397b4 commit ea6271d

File tree

11 files changed

+116
-249
lines changed

11 files changed

+116
-249
lines changed

CHANGELOG.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ Whitespace conventions:
1818
- 1 spaces before normal text
1919
-->
2020

21-
## [0.8.9] - FILL-IN FILL-IN
22-
23-
### Fixed
24-
25-
- Gets rid of react warnings about updating state during render (#155)
26-
- Multiple HAML classes (i.e. div.foo.bar) was not working (regression introduced in 0.8.8)
27-
- Don't send nil (null) to form components as the value string (#157)
28-
- Process `params` (props) correctly when using `Element#on` or `Element#render` (#158)
29-
- Deprecate shallow param compare (#156)
30-
31-
3221
## [0.8.8] - 2016-07-13
3322

3423
### Added

lib/react/api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def self.native_react_component?(name)
3737
end
3838

3939
def self.create_native_react_class(type)
40-
raise "Provided class should define `render` method" if !(type.respond_to? :render)
40+
raise "Provided class should define `render` method" if !(type.method_defined? :render)
4141
render_fn = (type.method_defined? :_render_wrapper) ? :_render_wrapper : :render
4242
# this was hashing type.to_s, not sure why but .to_s does not work as it Foo::Bar::View.to_s just returns "View"
4343
@@component_classes[type] ||= %x{

lib/react/component.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ def update_react_js_state(object, name, value)
113113
end
114114
end
115115

116-
# def render
117-
# raise 'no render defined'
118-
# end unless respond_to?(:render)
116+
def render
117+
raise 'no render defined'
118+
end unless method_defined?(:render)
119119

120120
def _render_wrapper
121121
State.set_state_context_to(self, true) do

lib/react/component/class_methods.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module React
22
module Component
33
# class level methods (macros) for components
44
module ClassMethods
5+
56
def reactrb_component?
67
true
78
end
@@ -28,26 +29,15 @@ def append_backtrace(message_array, backtrace)
2829
end
2930

3031
def render(container = nil, params = {}, &block)
31-
if container
32-
container = container.type if container.is_a? React::Element
33-
define_method :render do
32+
define_method :render do
33+
if container
3434
React::RenderingContext.render(container, params) { instance_eval(&block) if block }
35+
else
36+
instance_eval(&block)
3537
end
36-
else
37-
define_method(:render) { instance_eval(&block) }
3838
end
3939
end
4040

41-
# method missing will assume the method is a class name, and will treat this a render of
42-
# of the component, i.e. Foo::Bar.baz === Foo::Bar().baz
43-
44-
def method_missing(name, *args, &children)
45-
Object.method_missing(name, *args, &children) unless args.empty?
46-
React::RenderingContext.render(
47-
self, class: React::Element.haml_class_name(name), &children
48-
)
49-
end
50-
5141
def validator
5242
@validator ||= Validator.new(self)
5343
end

lib/react/component/tags.rb

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
# class HtmlTagWrapper
2-
# def initialize(name)
3-
# @name = name
4-
# end
5-
# def to_s
6-
# @name
7-
# end
8-
# def method_missing(n)
9-
#
10-
# end
11-
12-
131
module React
142
module Component
153
# contains the name of all HTML tags, and the mechanism to register a component
@@ -38,34 +26,18 @@ def present_as_node(component, *params, &children)
3826

3927
# define each predefined tag as an instance method
4028

41-
42-
43-
4429
HTML_TAGS.each do |tag|
4530
define_method(tag) do |*params, &children|
4631
React::RenderingContext.render(tag, *params, &children)
4732
end
48-
if tag != :div
49-
alias_method tag.upcase, tag
50-
const_set tag.upcase, tag
51-
else
52-
alias_method tag.upcase, tag
53-
#const_set tag.upcase, React.create_element(tag)
54-
#Object.const_set tag.upcase, Class.new(HtmlTagWrapper)
55-
end
33+
alias_method tag.upcase, tag
34+
const_set tag.upcase, tag
5635
# handle deprecated _as_node style
5736
define_method("#{tag}_as_node") do |*params, &children|
5837
React::RenderingContext.build_only(tag, *params, &children)
5938
end
6039
end
6140

62-
def self.html_tag_class_for(tag)
63-
downcased_tag = tag.downcase
64-
if tag =~ /[A-Z]+/ && HTML_TAGS.include?(downcased_tag)
65-
Object.const_set tag, React.create_element(downcased_tag)
66-
end
67-
end
68-
6941
# use method_missing to look up component names in the form of "Foo(..)"
7042
# where there is no preceeding scope.
7143

@@ -120,8 +92,6 @@ def find_component(name)
12092

12193
def lookup_const(name)
12294
return nil unless name =~ /^[A-Z]/
123-
#html_tag = React::Component::Tags.html_tag_class(name)
124-
#return html_tag if html_tag
12595
scopes = self.class.name.to_s.split('::').inject([Module]) do |nesting, next_const|
12696
nesting + [nesting.last.const_get(next_const)]
12797
end.reverse

lib/react/element.rb

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def on(*event_names, &block)
4444
# Used for elements that are not yet in DOM, i.e. they are provided as children
4545
# or they have been explicitly removed from the rendering context using the delete method.
4646

47-
def render(props = {}, &new_block)
47+
def render(props = {})
4848
if props.empty?
4949
React::RenderingContext.render(self)
5050
else
5151
props = API.convert_props(props)
5252
React::RenderingContext.render(
5353
Element.new(`React.cloneElement(#{to_n}, #{props.shallow_to_n})`,
54-
type, properties.merge(props), block),
54+
type, properties.merge(props), block)
5555
)
5656
end
5757
end
@@ -77,34 +77,20 @@ def as_node
7777
# params may be provide to each class (but typically only to the last for easy reading.)
7878

7979
def method_missing(class_name, args = {}, &new_block)
80-
return dup.render.method_missing(class_name, args, &new_block) unless rendered?
81-
React::RenderingContext.replace(
82-
self,
83-
RenderingContext.build do
84-
RenderingContext.render(type, build_new_properties(class_name, args), &new_block)
85-
end
86-
)
87-
end
88-
89-
def rendered?
90-
React::RenderingContext.rendered? self
91-
end
92-
93-
def self.haml_class_name(class_name)
94-
class_name.gsub(/__|_/, '__' => '_', '_' => '-')
95-
end
96-
97-
private
98-
99-
def build_new_properties(class_name, args)
100-
class_name = self.class.haml_class_name(class_name)
80+
class_name = class_name.gsub(/__|_/, '__' => '_', '_' => '-')
10181
new_props = properties.dup
10282
new_props[:className] = "\
10383
#{class_name} #{new_props[:className]} #{args.delete(:class)} #{args.delete(:className)}\
10484
".split(' ').uniq.join(' ')
10585
new_props.merge! args
86+
React::RenderingContext.replace(
87+
self,
88+
RenderingContext.build { RenderingContext.render(type, new_props, &new_block) }
89+
)
10690
end
10791

92+
private
93+
10894
# built in events, events going to native components, and events going to reactrb
10995

11096
# built in events will have their event param translated to the Event wrapper

lib/react/object.rb

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

0 commit comments

Comments
 (0)