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/context_wrapper.rb', line 9
def Consumer(*args, &block)
%x{
let operabu = Opal.React.render_buffer;
let props = null;
if (args.length > 0) { props = Opal.React.to_native_react_props(args[0]); }
let react_element = Opal.global.React.createElement(this.native.Consumer, props, function(value) {
let children = null;
if (block !== nil) {
operabu.push([]);
// console.log("consumer pushed", operabu, operabu.toString());
let block_result = block.$call();
if (block_result && block_result !== nil) { Opal.React.render_block_result(block_result); }
// 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(react_element);
}
end
|