Sha256: 02c53d0107cc30a8240e2e8dd1f57baf096818c658cdb2e3c7e71781cc90812a

Contents?: true

Size: 1.06 KB

Versions: 34

Compression:

Stored size: 1.06 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([]);
            Opal.React.active_components.push(base);
            #{base.new(`props`).instance_exec(&`base.function_block`)};
            Opal.React.active_components.pop();
            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

34 entries across 34 versions & 1 rubygems

Version Path
isomorfeus-react-16.10.4 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.3 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.2 lib/react/memo_component/creator.rb
isomorfeus-react-16.10.1 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.24 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.23 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.22 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.21 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.20 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.19 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.18 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.17 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.16 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.15 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.14 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.13 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.12 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.11 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.10 lib/react/memo_component/creator.rb
isomorfeus-react-16.9.9 lib/react/memo_component/creator.rb