module React
class HtmlTagWrapper
def initialize(name) @name = name end def to_s @name end def method_missing(n)
end
rubocop:disable Style/FileName require 'reactrb/deep-compare' to get 0.9 deep compare behavior
removes generation of the deprecated “_onXXXX” event param syntax
Constants
- ATTRIBUTES
- HASH_ATTRIBUTES
- HTML_TAGS
- VERSION
Public Class Methods
clear_component_class_cache()
click to toggle source
# File lib/react/api.rb, line 126 def self.clear_component_class_cache @@component_classes = {} end
convert_props(properties)
click to toggle source
# File lib/react/api.rb, line 130 def self.convert_props(properties) raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash props = {} properties.map do |key, value| if key == "class_name" && value.is_a?(Hash) props[lower_camelize(key)] = `React.addons.classSet(#{value.to_n})` elsif key == "class" props["className"] = value elsif ["style", "dangerously_set_inner_HTML"].include? key props[lower_camelize(key)] = value.to_n elsif React::HASH_ATTRIBUTES.include?(key) && value.is_a?(Hash) value.each { |k, v| props["#{key}-#{k.tr('_', '-')}"] = v.to_n } else props[React.html_attr?(lower_camelize(key)) ? lower_camelize(key) : key] = value end end props end
create_element(type, properties = {}, &block)
click to toggle source
# File lib/react/top_level.rb, line 53 def self.create_element(type, properties = {}, &block) React::API.create_element(type, properties, &block) end
html_attr?(name)
click to toggle source
# File lib/react/top_level.rb, line 42 def self.html_attr?(name) attrs = ATTRIBUTES %x{ for(var i = 0; i < attrs.length; i++) { if(attrs[i] === name) return true; } return false; } end
html_tag?(name)
click to toggle source
# File lib/react/top_level.rb, line 31 def self.html_tag?(name) tags = HTML_TAGS %x{ for(var i = 0; i < tags.length; i++) { if(tags[i] === name) return true; } return false; } end
is_valid_element(element)
click to toggle source
# File lib/react/top_level.rb, line 71 def self.is_valid_element(element) element.kind_of?(React::Element) && `React.isValidElement(#{element.to_n})` end
render(element, container)
click to toggle source
# File lib/react/top_level.rb, line 57 def self.render(element, container) container = `container.$$class ? container[0] : container` if !(`typeof ReactDOM === 'undefined'`) component = Native(`ReactDOM.render(#{element.to_n}, container, function(){#{yield if block_given?}})`) # v0.15+ elsif !(`typeof React.renderToString === 'undefined'`) component = Native(`React.render(#{element.to_n}, container, function(){#{yield if block_given?}})`) else raise "render is not defined. In React >= v15 you must import it with ReactDOM" end component.class.include(React::Component::API) component end
render_to_static_markup(element)
click to toggle source
# File lib/react/top_level.rb, line 85 def self.render_to_static_markup(element) if !(`typeof ReactDOMServer === 'undefined'`) React::RenderingContext.build { `ReactDOMServer.renderToStaticMarkup(#{element.to_n})` } # v0.15+ elsif !(`typeof React.renderToString === 'undefined'`) React::RenderingContext.build { `React.renderToStaticMarkup(#{element.to_n})` } else raise "renderToStaticMarkup is not defined. In React >= v15 you must import it with ReactDOMServer" end end
render_to_string(element)
click to toggle source
# File lib/react/top_level.rb, line 75 def self.render_to_string(element) if !(`typeof ReactDOMServer === 'undefined'`) React::RenderingContext.build { `ReactDOMServer.renderToString(#{element.to_n})` } # v0.15+ elsif !(`typeof React.renderToString === 'undefined'`) React::RenderingContext.build { `React.renderToString(#{element.to_n})` } else raise "renderToString is not defined. In React >= v15 you must import it with ReactDOMServer" end end
unmount_component_at_node(node)
click to toggle source
# File lib/react/top_level.rb, line 95 def self.unmount_component_at_node(node) if !(`typeof ReactDOM === 'undefined'`) `ReactDOM.unmountComponentAtNode(node.$$class ? node[0] : node)` # v0.15+ elsif !(`typeof React.renderToString === 'undefined'`) `React.unmountComponentAtNode(node.$$class ? node[0] : node)` else raise "unmountComponentAtNode is not defined. In React >= v15 you must import it with ReactDOM" end end
Private Class Methods
lower_camelize(snake_cased_word)
click to toggle source
# File lib/react/api.rb, line 151 def self.lower_camelize(snake_cased_word) words = snake_cased_word.split('_') result = [words.first] result.concat(words[1..-1].map {|word| word[0].upcase + word[1..-1] }) result.join('') end