<commit_before>/* @flow */

import type VueRouter from '../index'
import { assert } from '../util/warn'
import { cleanPath } from '../util/path'
import { History } from './base'
import {
  saveScrollPosition,
  getScrollPosition,
  isValidPosition,
  normalizePosition,
  getElementPosition
} from '../util/scroll-position'

const genKey = () => String(Date.now())
let _key: string = genKey()

export class HTML5History extends History {
  constructor (router: VueRouter, base: ?string) {
    super(router, base)

    const expectScroll = router.options.scrollBehavior
    window.addEventListener('popstate', e => {
      _key = e.state && e.state.key
      const current = this.current
      this.transitionTo(getLocation(this.base), next => {
        if (expectScroll) {
          this.handleScroll(next, current, true)
        }
      })<commit_msg>make use of user timing api if available (#998)<commit_after>/* @flow */

import type VueRouter from '../index'
import { assert } from '../util/warn'
import { inBrowser } from '../util/dom'
import { cleanPath } from '../util/path'
import { History } from './base'
import {
  saveScrollPosition,
  getScrollPosition,
  isValidPosition,
  normalizePosition,
  getElementPosition
} from '../util/scroll-position'

// use User Timing api (if present) for more accurate key precision
const Time = inBrowser ? (window.performance || Date) : Date

const genKey = () => String(Time.now())
let _key: string = genKey()

export class HTML5History extends History {
  constructor (router: VueRouter, base: ?string) {
    super(router, base)

    const expectScroll = router.options.scrollBehavior
    window.addEventListener('popstate', e => {
      _key = e.state && e.state.key
      const current = this.current
      this.transitionTo(getLocation(this.base), next => {
        if (expectScroll) {
          this.handleScroll(next, current, true)
        }
      })
{'fraction_non_alphanumeric': 0.12945492662473795, 'fraction_numerical': 0.002620545073375262, 'mean_word_length': 3.328798185941043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6160472', 'n_tokens_mistral': 552, 'n_tokens_neox': 542, 'n_words': 157}