Sha256: 3e2850147b2f1add1be3f8dfb739b46a80ab7e5a3bfa95696aedb4cf57d67fd5

Contents?: true

Size: 1.32 KB

Versions: 20

Compression:

Stored size: 1.32 KB

Contents

module React
  module Component
    module API
      def dom_node
        if !(`typeof ReactDOM === 'undefined' || typeof ReactDOM.findDOMNode === 'undefined'`)
          `ReactDOM.findDOMNode(#{self}.native)` # v0.14.0
        elsif !(`typeof React.findDOMNode === 'undefined'`)
          `React.findDOMNode(#{self}.native)`    # v0.13.0
        else
          `#{self}.native.getDOMNode`            # v0.12.0
        end
      end

      def mounted?
        `#{self}.native.isMounted()`
      end

      def force_update!
        `#{self}.native.forceUpdate()`
      end

      def set_props(prop, &block)
        set_or_replace_state_or_prop(prop, 'setProps', &block)
      end

      def set_props!(prop, &block)
        set_or_replace_state_or_prop(prop, 'replaceProps', &block)
      end

      def set_state(state, &block)
        set_or_replace_state_or_prop(state, 'setState', &block)
      end

      def set_state!(state, &block)
        set_or_replace_state_or_prop(state, 'replaceState', &block)
      end

      private

      def set_or_replace_state_or_prop(state_or_prop, method, &block)
        raise "No native ReactComponent associated" unless @native
        %x{
          #{@native}[#{method}](#{state_or_prop.shallow_to_n}, function(){
            #{block.call if block}
          });
        }
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
hyper-react-0.12.7 lib/react/component/api.rb
hyper-react-0.12.6 lib/react/component/api.rb
hyper-react-0.12.5 lib/react/component/api.rb
hyper-react-0.12.4 lib/react/component/api.rb
hyper-react-0.12.3 lib/react/component/api.rb
hyper-react-0.12.2 lib/react/component/api.rb
hyper-react-0.12.1 lib/react/component/api.rb
hyper-react-0.12.0 lib/react/component/api.rb
hyper-react-0.11.0 lib/react/component/api.rb
hyper-react-0.10.0 lib/react/component/api.rb
reactrb-0.9.0 lib/react/component/api.rb
reactrb-0.8.8 lib/react/component/api.rb
reactrb-0.8.7 lib/react/component/api.rb
reactrb-0.8.6 lib/react/component/api.rb
reactrb-0.8.5 lib/react/component/api.rb
reactrb-0.8.4 lib/react/component/api.rb
reactrb-0.8.3 lib/react/component/api.rb
reactrb-0.8.1 lib/react/component/api.rb
reactrb-0.8.0 lib/react/component/api.rb
reactrb-0.7.42 lib/react/component/api.rb