Sha256: 0edd323f6735282e09721ae3fd0fc6cb8ab7ac996ed844f12fc6c7281484d430

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

module React
  module MemoComponent
    module Creator
      def self.extended(base)
        %x{
          base.equality_checker = null;
          base.react_component = Opal.global.React.memo(function(props) {
            Opal.React.render_buffer.push([]);
            // console.log("memo pushed", Opal.React.render_buffer, Opal.React.render_buffer.toString());
            Opal.React.active_components.push(base);
            let block_result = #{base.new(`props`).instance_exec(&`base.function_block`)};
            if (block_result && (block_result.constructor === String || block_result.constructor === Number)) { Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(block_result); }
            Opal.React.active_components.pop();
            // console.log("memo popping", Opal.React.render_buffer, Opal.React.render_buffer.toString());
            return Opal.React.render_buffer.pop();
          }, base.equality_checker);
        }

        def props_are_equal?(&block)
          %x{
            base.equality_checker = function (prev_props, next_props) {
              var prev_ruby_props = Opal.React.Component.Props.$new({props: prev_props});
              var next_ruby_props = Opal.React.Component.Props.$new({props: next_props});
              return #{base.new(`{}`).instance_exec(`prev_ruby_props`, `next_ruby_props`, &block)};
            }
          }
        end

        def create_memo(&block)
          `base.function_block = #{block}`
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
isomorfeus-react-16.11.0 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.17 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.16 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.14 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.13 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.12 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.11 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.10 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.9 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.8 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.7 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.6 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.5 lib/react/memo_component/creator.rb