Module: ReactDOM
- Defined in:
- lib/react_dom.rb
Class Method Summary collapse
- .create_portal(child, container) ⇒ Object
- .find_dom_node(native_react_component) ⇒ Object
- .hydrate(native_react_element, container, &block) ⇒ Object
- .render(native_react_element, container, &block) ⇒ Object
- .unmount_component_at_node(element_or_query) ⇒ Object
Class Method Details
.create_portal(child, container) ⇒ Object
3 4 5 6 |
# File 'lib/react_dom.rb', line 3 def create_portal(child, container) # container is a native DOM node `Opal.global.ReactDOM.createPortal(child, container)` end |
.find_dom_node(native_react_component) ⇒ Object
8 9 10 |
# File 'lib/react_dom.rb', line 8 def find_dom_node(native_react_component) `Opal.global.ReactDOM.findDomNode(native_react_component)` end |
.hydrate(native_react_element, container, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/react_dom.rb', line 12 def hydrate(native_react_element, container, &block) # container is a native DOM element `Opal.React.render_buffer.push([]);` result = if block_given? `Opal.global.ReactDOM.hydrate(native_react_element, container, function() { block.$call() })` else `Opal.global.ReactDOM.hydrate(native_react_element, container)` end `Opal.React.render_buffer.pop()` result end |
.render(native_react_element, container, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/react_dom.rb', line 24 def render(native_react_element, container, &block) # container is a native DOM element `Opal.React.render_buffer.push([]);` result = if block_given? `Opal.global.ReactDOM.render(native_react_element, container, function() { block.$call() })` else `Opal.global.ReactDOM.render(native_react_element, container)` end `Opal.React.render_buffer.pop()` result end |
.unmount_component_at_node(element_or_query) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/react_dom.rb', line 36 def unmount_component_at_node(element_or_query) 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 `Opal.global.ReactDOM.unmountComponentAtNode(element)` end |