Class: Preact::ContextWrapper
- Includes:
- Native::Wrapper
- Defined in:
- lib/preact/context_wrapper.rb
Instance Method Summary collapse
- #Consumer(*args, &block) ⇒ Object
-
#initialize(native) ⇒ ContextWrapper
constructor
A new instance of ContextWrapper.
- #is_wrapped_context ⇒ Object
- #Provider(*args, &block) ⇒ Object
Constructor Details
#initialize(native) ⇒ ContextWrapper
Returns a new instance of ContextWrapper.
5 6 7 |
# File 'lib/preact/context_wrapper.rb', line 5 def initialize(native) @native = native end |
Instance Method Details
#Consumer(*args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/preact/context_wrapper.rb', line 13 def Consumer(*args, &block) %x{ let operabu = Opal.Preact.render_buffer; let props = null; if (args.length > 0) { props = Opal.Preact.to_native_preact_props(args[0]); } let preact_element = Opal.global.Preact.createElement(this.native.Consumer, props, function(value) { let children = null; if (block !== nil) { operabu.push([]); // console.log("consumer pushed", operabu, operabu.toString()); try { let block_result = block.$call(value); if (block_result && block_result !== nil) { Opal.Preact.render_block_result(block_result); } } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); } // console.log("consumer popping", operabu, operabu.toString()); children = operabu.pop(); if (children.length === 1) { children = children[0]; } else if (children.length === 0) { children = null; } } return children; }); operabu[operabu.length - 1].push(preact_element); } end |
#is_wrapped_context ⇒ Object
9 10 11 |
# File 'lib/preact/context_wrapper.rb', line 9 def is_wrapped_context true end |
#Provider(*args, &block) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/preact/context_wrapper.rb', line 40 def Provider(*args, &block) %x{ var props = null; if (args.length > 0) { props = Opal.Preact.to_native_preact_props(args[0]); } Opal.Preact.internal_render(this.native.Provider, props, null, block); } end |