Sha256: afab0564bbe431fe7f9cb5916ae35016294b7bba7f3ab710d5dc411657bb895c

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

module React
  module Component
    class History
      include ::Native::Wrapper

      def initialize(native)
        @native = native
      end
      
      def block(prompt)
        @native.JS[:props].JS[:history].JS.block(prompt)
      end

      def create_href(location)
        @native.JS[:props].JS[:history].JS.createHref(location)
      end

      def go(n)
        @native.JS[:props].JS[:history].JS.go(n)
      end

      def go_back
        @native.JS[:props].JS[:history].JS.goBack()
      end

      def go_forward
        @native.JS[:props].JS[:history].JS.goForward()
      end

      def push(*args)
        @native.JS[:props].JS[:history].JS.push(*args)
      end

      def replace(*args)
        @native.JS[:props].JS[:history].JS.replace(*args)
      end

      def method_missing(prop, *args, &block)
        @native.JS[:props].JS[:history].JS[prop]
      end

      def listen(&block)
        fun = nil
        %x{
          fun = function(location, action) {
            let ruby_location = #{React::Component::Location.new(`{ props: { location: location }}`)}
            block.$call(ruby_location, action);
          }
        }
        unlisten = @native.JS[:props].JS[:history].JS.listen(fun)
        -> { unlisten.JS.call() }
      end

      def location
        return @location if @location
        return nil unless @native.JS[:props].JS[:history].JS[:location]
        if @native.JS[:props].JS[:history].JS[:location].JS[:pathname]
          @location = React::Component::Location.new(@native)
        else
          @native.JS[:props].JS[:history].JS[:location]
        end
      end

      def to_n
        @native.JS[:props].JS[:history]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
isomorfeus-react-16.13.12 lib/react/component/history.rb