Sha256: 3ac4fedc23b2da8b72962a9bdedbe8d19a59734be3866bb4222e8dfc11b8320a

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'react/component'

module Hyperloop
  module Vis
    module Mixin
      def self.included(base)
        base.include(Hyperloop::Component::Mixin)
        base.class_eval do
          param data: nil

          def _set_dom_node(dom_node)
            @_dom_node = dom_node
          end

          def data
            @_data
          end
          
          def self.render_with_dom_node(tag = 'DIV', &block)
            render do
              @_vis_render_block = block
              @_data = params.data
              send(tag, ref: method(:_set_dom_node).to_proc)
            end
          end

          def should_component_update?
            false
          end

          after_mount do
            if @_dom_node && @_vis_render_block
              @_vis_render_block.call(@_dom_node, @_data)
            end
          end

          before_receive_props do |new_props|
            if new_props[:data] != @_data
              @_data = new_props[:data] 
              if @_dom_node && @_vis_render_block
                @_vis_render_block.call(@_dom_node, @_data)
              end
            end
          end
        end
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hyper-vis-1.0.0.lap24 lib/hyperloop/vis/mixin.rb