module React
Constants
- VERSION
Public Class Methods
clone_element(ruby_react_element, props = nil, children = nil, &block)
click to toggle source
# File lib/react.rb, line 222 def self.clone_element(ruby_react_element, props = nil, children = nil, &block) block_result = `null` if block_given? block_result = block.call block_result = `null` unless block_result end native_props = props ? `Opal.React.to_native_react_props(props)` : `null` `Opal.global.React.cloneElement(ruby_react_element.$to_n(), native_props, block_result)` end
create_context(const_name, default_value)
click to toggle source
# File lib/react.rb, line 232 def self.create_context(const_name, default_value) %x{ Opal.global[const_name] = Opal.global.React.createContext(default_value); var new_const = #{React::ContextWrapper.new(`Opal.global[const_name]`)}; #{Object.const_set(const_name, `new_const`)}; return new_const; } end
create_element(type, props = nil, children = nil, &block)
click to toggle source
# File lib/react.rb, line 241 def self.create_element(type, props = nil, children = nil, &block) %x{ const operabu = self.render_buffer; let component = null; let native_props = null; if (typeof type.react_component !== 'undefined') { component = type.react_component; } else { component = type; } if (block !== nil) { operabu.push([]); // console.log("create_element pushed", Opal.React.render_buffer, Opal.React.render_buffer.toString()); let block_result = block.$call(); if (block_result && block_result !== nil) { Opal.React.render_block_result(block_result); } // console.log("create_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString()); children = operabu.pop(); } else if (children === nil) { children = []; } else if (typeof children === 'string') { children = [children]; } if (props && props !== nil) { native_props = self.to_native_react_props(props); } return Opal.global.React.createElement.apply(this, [component, native_props].concat(children)); } end
create_factory(type)
click to toggle source
# File lib/react.rb, line 262 def self.create_factory(type) native_function = `Opal.global.React.createFactory(type)` proc { `native_function.call()` } end
create_ref()
click to toggle source
# File lib/react.rb, line 267 def self.create_ref React::Ref.new(`Opal.global.React.createRef()`) end
forwardRef(&block)
click to toggle source
# File lib/react.rb, line 271 def self.forwardRef(&block) # TODO whats the return here? A React:Element?, doc says a React node, whats that? `Opal.global.React.forwardRef( function(props, ref) { return block.$call().$to_n(); })` end
is_valid_element(react_element)
click to toggle source
# File lib/react.rb, line 276 def self.is_valid_element(react_element) `Opal.global.React.isValidElement(react_element)` end
lazy(import_statement_function)
click to toggle source
# File lib/react.rb, line 280 def self.lazy(import_statement_function) `Opal.global.React.lazy(import_statement_function)` end
memo(function_component, &block)
click to toggle source
# File lib/react.rb, line 284 def self.memo(function_component, &block) if block_given? %x{ var fun = function(prev_props, next_props) { return #{block.call(::React::Component::Props.new(`{props: prev_props}`), ::React::Component::Props.new(`{props: next_props}`))}; } return Opal.global.React.memo(function_component, fun); } else `Opal.global.React.memo(function_component)` end end