Module: React

Defined in:
lib/react.rb,
lib/react/ref.rb,
lib/react/version.rb,
lib/react/children.rb,
lib/react_native/react.rb,
lib/react/component/api.rb,
lib/react/component/base.rb,
lib/react/component/match.rb,
lib/react/component/mixin.rb,
lib/react/component/props.rb,
lib/react/component/state.rb,
lib/react/context_wrapper.rb,
lib/react/synthetic_event.rb,
lib/react/component/styles.rb,
lib/react/component/history.rb,
lib/react/component/elements.rb,
lib/react/component/features.rb,
lib/react/component/location.rb,
lib/react/component/callbacks.rb,
lib/react/component/resolution.rb,
lib/react/component/initializer.rb,
lib/react/native_constant_wrapper.rb,
lib/isomorfeus_react/react/memo_component/base.rb,
lib/isomorfeus_react/react/memo_component/mixin.rb,
lib/react/component/native_component_constructor.rb,
lib/isomorfeus_react/react/function_component/api.rb,
lib/isomorfeus_react/react/function_component/base.rb,
lib/isomorfeus_react/react/function_component/mixin.rb,
lib/isomorfeus_react/react/function_component/initializer.rb,
lib/isomorfeus_react/react/memo_component/native_component_constructor.rb,
lib/isomorfeus_react/react/function_component/native_component_constructor.rb

Defined Under Namespace

Modules: Children, Component, FunctionComponent, MemoComponent Classes: ContextWrapper, NativeConstantWrapper, Ref, SyntheticEvent

Constant Summary collapse

VERSION =
'16.13.12'

Class Method Summary collapse

Class Method Details

.clone_element(ruby_react_element, props = nil, children = nil, &block) ⇒ Object



222
223
224
225
226
227
228
229
230
# 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) ⇒ Object



232
233
234
235
236
237
238
239
# 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) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# 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) ⇒ Object



262
263
264
265
# File 'lib/react.rb', line 262

def self.create_factory(type)
  native_function = `Opal.global.React.createFactory(type)`
  proc { `native_function.call()` }
end

.create_refObject



267
268
269
# File 'lib/react.rb', line 267

def self.create_ref
  React::Ref.new(`Opal.global.React.createRef()`)
end

.forwardRef(&block) ⇒ Object



271
272
273
274
# 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) ⇒ Object



276
277
278
# File 'lib/react.rb', line 276

def self.is_valid_element(react_element)
  `Opal.global.React.isValidElement(react_element)`
end

.lazy(import_statement_function) ⇒ Object



280
281
282
# File 'lib/react.rb', line 280

def self.lazy(import_statement_function)
  `Opal.global.React.lazy(import_statement_function)`
end

.memo(function_component, &block) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
# 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