97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/react/api.rb', line 97
def self.create_element(type, properties = {}, &block)
params = []
if @@component_classes[type]
params << @@component_classes[type]
elsif type.kind_of?(Class)
params << create_native_react_class(type)
elsif React::Component::Tags::HTML_TAGS.include?(type)
params << type
elsif type.is_a? String
return React::Element.new(type)
else
raise "#{type} not implemented"
end
properties = convert_props(properties)
params << properties.shallow_to_n
if block_given?
[yield].flatten.each do |ele|
params << ele.to_n
end
end
React::Element.new(`React.createElement.apply(null, #{params})`, type, properties, block)
end
|