<commit_before>import React from 'react';
import assign from 'object-assign';
import History from './History';
import Location from './Location';
import { getWindowScrollPosition } from './DOMUtils';

/**
 * A history interface that assumes a DOM environment.
 */
class DOMHistory extends History {

  static propTypes = assign({
    getScrollPosition: React.PropTypes.func.isRequired
  }, History.propTypes);

  static defaultProps = assign({
    getScrollPosition: getWindowScrollPosition
  }, History.defaultProps);

  static childContextTypes = assign({}, History.childContextTypes);

  constructor(props, context) {
    super(props, context);
    this.scrollHistory = {};
  }

  createLocation(path, query, navigationType, key) {
    var fullPath = this.makePath(path, query);
    var scrollPosition = this.scrollHistory[fullPath];

    return new Location(path, query, navigationType, key, scrollPosition);
  }

  go(n) {
    if (n === 0)
      return;

    window.history.go(n);
  }

  recordScrollPosition() {
    var renderedLocation = this.state.location;
    var renderedFullPath = this.makePath(renderedLocation.path, renderedLocation.query);

    this.scrollHistory[renderedFullPath] = this.props.getScrollPosition();
  }

}

export default DOMHistory;
<commit_msg>Use location.key for storing scroll position when available<commit_after>import React from 'react';
import assign from 'object-assign';
import History from './History';
import Location from './Location';
import { getWindowScrollPosition } from './DOMUtils';

/**
 * A history interface that assumes a DOM environment.
 */
class DOMHistory extends History {

  static propTypes = assign({
    getScrollPosition: React.PropTypes.func.isRequired
  }, History.propTypes);

  static defaultProps = assign({
    getScrollPosition: getWindowScrollPosition
  }, History.defaultProps);

  static childContextTypes = assign({}, History.childContextTypes);

  constructor(props, context) {
    super(props, context);
    this.scrollHistory = {};
  }

  getScrollKey(path, query, key) {
    return key || this.makePath(path, query);
  }

  createLocation(path, query, navigationType, key) {
    var scrollKey = this.getScrollKey(path, query, key);
    var scrollPosition = this.scrollHistory[scrollKey];

    return new Location(path, query, navigationType, key, scrollPosition);
  }

  go(n) {
    if (n === 0)
      return;

    window.history.go(n);
  }

  recordScrollPosition() {
    var location = this.state.location;
    var scrollKey = this.getScrollKey(location.path, location.query, location.key);

    this.scrollHistory[scrollKey] = this.props.getScrollPosition();
  }

}

export default DOMHistory;

{'fraction_non_alphanumeric': 0.11459499813363196, 'fraction_numerical': 0.0007465472191116088, 'mean_word_length': 4.1937984496124034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4473149', 'n_tokens_mistral': 761, 'n_tokens_neox': 734, 'n_words': 196}