Sha256: e314444a6aa8a5e7e87fd2955aa450bd1df032284bd988b0e9b4b4057b3c9ddb

Contents?: true

Size: 1.46 KB

Versions: 42

Compression:

Stored size: 1.46 KB

Contents

module Preact
  class ContextWrapper
    include ::Native::Wrapper

    def initialize(native)
      @native = native
    end
    
    def is_wrapped_context
      true
    end

    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());
            let block_result = block.$call(value);
            if (block_result && block_result !== nil) { Opal.Preact.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(preact_element);
      }
    end

    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
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
isomorfeus-preact-10.6.29 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.28 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.27 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.26 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.25 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.24 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.23 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.22 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.21 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.20 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.19 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.18 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.17 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.16 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.15 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.14 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.13 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.12 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.11 lib/preact/context_wrapper.rb
isomorfeus-preact-10.6.10 lib/preact/context_wrapper.rb