Module: React

Defined in:
lib/reactrb/deep-compare.rb,
lib/react/api.rb,
lib/react/test.rb,
lib/react/event.rb,
lib/react/server.rb,
lib/react/element.rb,
lib/react/children.rb,
lib/react/test/dsl.rb,
lib/react/callbacks.rb,
lib/react/component.rb,
lib/react/component.rb,
lib/react/top_level.rb,
lib/react/validator.rb,
lib/react/test/utils.rb,
lib/react/ref_callback.rb,
lib/react/test/session.rb,
lib/react/component/api.rb,
lib/react/config/server.rb,
lib/react/component/base.rb,
lib/react/component/tags.rb,
lib/react/native_library.rb,
lib/reactive-ruby/version.rb,
lib/react/component/params.rb,
lib/react/top_level_render.rb,
lib/react/rendering_context.rb,
lib/react/component/class_methods.rb,
lib/react/component/props_wrapper.rb,
lib/reactive-ruby/isomorphic_helpers.rb,
lib/reactrb/new-event-name-convention.rb,
lib/react/component/dsl_instance_methods.rb,
lib/rails-helpers/top_level_rails_component.rb,
lib/react/component/should_component_update.rb,
lib/react/test/matchers/render_html_matcher.rb

Overview

removes generation of the deprecated “_onXXXX” event param syntax

Defined Under Namespace

Modules: Callbacks, Component, ComponentNoNotice, Config, IsomorphicHelpers, RefsCallbackExtension, Server, Test Classes: API, Children, Element, Event, NativeLibrary, RenderingContext, TopLevelRailsComponent, Validator

Constant Summary collapse

ATTRIBUTES =
%w(accept acceptCharset accessKey action allowFullScreen allowTransparency alt
async autoComplete autoPlay cellPadding cellSpacing charSet checked classID
className cols colSpan content contentEditable contextMenu controls coords
crossOrigin data dateTime defer dir disabled download draggable encType form
formAction formEncType formMethod formNoValidate formTarget frameBorder height
hidden href hrefLang htmlFor httpEquiv icon id label lang list loop manifest
marginHeight marginWidth max maxLength media mediaGroup method min multiple
muted name noValidate open pattern placeholder poster preload radioGroup
readOnly rel required role rows rowSpan sandbox scope scrolling seamless
selected shape size sizes span spellCheck src srcDoc srcSet start step style
tabIndex target title type useMap value width wmode dangerouslySetInnerHTML) +
#SVG ATTRIBUTES
%w(clipPath cx cy d dx dy fill fillOpacity fontFamily
fontSize fx fy gradientTransform gradientUnits markerEnd
markerMid markerStart offset opacity patternContentUnits
patternUnits points preserveAspectRatio r rx ry spreadMethod
stopColor stopOpacity stroke  strokeDasharray strokeLinecap
strokeOpacity strokeWidth textAnchor transform version
viewBox x1 x2 x xlinkActuate xlinkArcrole xlinkHref xlinkRole
xlinkShow xlinkTitle xlinkType xmlBase xmlLang xmlSpace y1 y2 y)
HASH_ATTRIBUTES =
%w(data aria)
HTML_TAGS =
React::Component::Tags::HTML_TAGS
VERSION =
"0.12.3"

Class Method Summary collapse

Class Method Details

.create_element(type, properties = {}, &block) ⇒ Object



53
54
55
# 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) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



77
78
79
80
# File 'lib/react/top_level.rb', line 77

def self.is_valid_element(element)
  %x{ console.error("Warning: `is_valid_element` is deprecated in favor of `is_valid_element?`."); }
  element.kind_of?(React::Element) && `React.isValidElement(#{element.to_n})`
end

.is_valid_element?(element) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/react/top_level.rb', line 82

def self.is_valid_element?(element)
  element.kind_of?(React::Element) && `React.isValidElement(#{element.to_n})`
end

.render(element, container) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/react/top_level.rb', line 57

def self.render(element, container)
  %x{
      console.error(
        "Warning: Using deprecated behavior of `React.render`,",
        "require \"react/top_level_render\" to get the correct behavior."
      );
  }
  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) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/react/top_level.rb', line 97

def self.render_to_static_markup(element)
  %x{ console.error("Warning: `React.render_to_static_markup` is deprecated in favor of `React::Server.render_to_static_markup`."); }
  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) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/react/top_level.rb', line 86

def self.render_to_string(element)
  %x{ console.error("Warning: `React.render_to_string` is deprecated in favor of `React::Server.render_to_string`."); }
  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) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/react/top_level.rb', line 108

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