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
32
33
# 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{
    let operabu = Opal.React.render_buffer;
    operabu.push([]);
    // console.log("portal pushed", operabu, operabu.toString());
    if (block !== nil) {
      let block_result = block.$call()
      let last_buffer_length = operabu[operabu.length - 1].length;
      let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
      if (block_result && block_result !== nil) { Opal.React.render_block_result(block_result); }
    }
    // console.log("portal popping", operabu, operabu.toString());
    let result = operabu.pop();
    if (result.length === 1) { result = result[0]; }
    var react_element = Opal.global.React.createPortal(result, element);
    operabu[operabu.length - 1].push(react_element);
    // console.log("portal pushed", operabu, operabu.toString());
  }
end

#Profiler(*args, &block) ⇒ Object



35
36
37
# File 'lib/react/component/features.rb', line 35

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

#StrictMode(*args, &block) ⇒ Object



39
40
41
# File 'lib/react/component/features.rb', line 39

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

#Suspense(*args, &block) ⇒ Object



43
44
45
# File 'lib/react/component/features.rb', line 43

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