Module: React::Component::Features

Defined in:
lib/react/component/features.rb

Instance Method Summary collapse

Instance Method Details

#Fragment(*args, &block) ⇒ Object



4
5
6
# File 'lib/react/component/features.rb', line 4

def Fragment(*args, &block)
  `Opal.React.internal_prepare_args_and_render(Opal.global.React.Fragment, args, block)`
end

#Portal(element_or_query, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/react/component/features.rb', line 8

def Portal(element_or_query, &block)
  if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
    element = `document.body.querySelector(element_or_query)`
  elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
    element = element_or_query.to_n
  else
    element = element_or_query
  end
  %x{
    var block_result = null;
    Opal.React.render_buffer.push([]);
    if (block !== nil) {
      block_result = block.$call()
      if (block_result && (block_result !== nil && (typeof block_result === "string" || typeof block_result.$$typeof === "symbol" ||
        (typeof block_result.constructor !== "undefined" && block_result.constructor === Array && block_result[0] && typeof block_result[0].$$typeof === "symbol")
        ))) {
        Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(block_result);
      }
    }
    var react_element = Opal.global.React.createPortal(Opal.React.render_buffer.pop(), element);
    Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(react_element);
    return null;
  }
end

#Profiler(*args, &block) ⇒ Object



33
34
35
# File 'lib/react/component/features.rb', line 33

def Profiler(*args, &block)
  `Opal.React.internal_prepare_args_and_render(Opal.global.React.Profiler, args, block)`
end

#StrictMode(*args, &block) ⇒ Object



37
38
39
# File 'lib/react/component/features.rb', line 37

def StrictMode(*args, &block)
  `Opal.React.internal_prepare_args_and_render(Opal.global.React.StrictMode, args, block)`
end

#Suspense(*args, &block) ⇒ Object



41
42
43
# File 'lib/react/component/features.rb', line 41

def Suspense(*args, &block)
  `Opal.React.internal_prepare_args_and_render(Opal.global.React.Suspense, args, block)`
end