Sha256: 238ad9c33ee074eae3ee3e3e0109ed216fd20a5a28f90639574ae1e1b3bc7f91

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# backtick_javascript: true

module Browser
  class History
    if RUBY_ENGINE == 'opal'
      include Native::Wrapper

      alias_native :back
      alias_native :forward
      alias_native :go

      native_reader :length
      alias :size :length

      def push_state(state, title = '', url = `null`)
        `#@native.pushState(Object.fromEntries(#{state}), #{title}, #{url})`
      end

      def replace_state(state, title = '', url = `null`)
        `#@native.replaceState(Object.fromEntries(#{state}), #{title}, #{url})`
      end

      def scroll_restoration
        `#@native.scrollRestoration`
      end

      def scroll_restoration=(s)
        `#@native.scrollRestoration = #{s}`
      end

      def state
        `Opal.hash(#@native.state)`
      end
    else
      def back; end
      def forward; end
      def go(_); end

      def length
        0
      end
      alias :size :length

      def push_state(state, title = '', url = nil); end
      def replace_state(state, title = '', url = nil); end
      def scroll_restoration; end
      def scroll_restoration=(s); end

      def state
        {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
isomorfeus-preact-23.8.0.rc3 lib/browser/history.rb
isomorfeus-preact-23.8.0.rc2 lib/browser/history.rb
isomorfeus-preact-23.8.0.rc1 lib/browser/history.rb