Sha256: 2e20e780fa1e079f1e9da63340bbe572f299788eda69c10264b8721a097c53d2

Contents?: true

Size: 1.52 KB

Versions: 27

Compression:

Stored size: 1.52 KB

Contents

module React
  class ContextWrapper
    include ::Native::Wrapper

    def is_wrapped_context
      true
    end

    def Consumer(*args, &block)
      # why not use internal_prepare_args and render?
      %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.constructor === String || block_result.constructor === Number)) {
              operabu[operabu.length - 1].push(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

    def Provider(*args, &block)
      # why not use internal_prepare_args and render?
      %x{
        var props = null;
        if (args.length > 0) { props = Opal.React.to_native_react_props(args[0]); }
        Opal.React.internal_render(this.native.Provider, props, null, block);
      }
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
isomorfeus-react-16.13.6 lib/react/context_wrapper.rb
isomorfeus-react-16.13.5 lib/react/context_wrapper.rb
isomorfeus-react-16.13.4 lib/react/context_wrapper.rb
isomorfeus-react-16.13.3 lib/react/context_wrapper.rb
isomorfeus-react-16.13.2 lib/react/context_wrapper.rb
isomorfeus-react-16.13.1 lib/react/context_wrapper.rb
isomorfeus-react-16.13.0 lib/react/context_wrapper.rb
isomorfeus-react-16.12.24 lib/react/context_wrapper.rb
isomorfeus-react-16.12.23 lib/react/context_wrapper.rb
isomorfeus-react-16.12.22 lib/react/context_wrapper.rb
isomorfeus-react-16.12.21 lib/react/context_wrapper.rb
isomorfeus-react-16.12.20 lib/react/context_wrapper.rb
isomorfeus-react-16.12.19 lib/react/context_wrapper.rb
isomorfeus-react-16.12.18 lib/react/context_wrapper.rb
isomorfeus-react-16.12.17 lib/react/context_wrapper.rb
isomorfeus-react-16.12.16 lib/react/context_wrapper.rb
isomorfeus-react-16.12.15 lib/react/context_wrapper.rb
isomorfeus-react-16.12.14 lib/react/context_wrapper.rb
isomorfeus-react-16.12.13 lib/react/context_wrapper.rb
isomorfeus-react-16.12.12 lib/react/context_wrapper.rb